0

I'd like to show minor ticks on a log-log plot, but I've not found a solution. The answer here doesn't seem to work as expected. My MWE is

%pylab inline
plot(array([10**x for x in range(-20,0)]), array([10**x for x in range(-20,0)]))
yscale('log')
xscale('log')
show()

and I would like to have ticks at, say, every decade, or every multiple of 3 and 10. How can I achieve this?

EDIT:

One particularly desirable behavior is to have a (minor, unlabelled) tick at every decade, and a (major, labelled) tick at every second or third decade, and to have the locations of the labelled ones be at my control. For example: I'd like to have the ability to make (..., 10^-6, 10^-3, 1, 10^3, ...) labelled and (...10^-5, 10^-4, 10^-2, 0.1, 10, 100, ...) unlabeled; or alternately (..., 10^-4, 10^-2, 1, 10^2, ...) labelled and (...10^-5, 10^-3, 0.1, 10, ...) unlabeled.

user1451632
  • 301
  • 1
  • 2
  • 10
  • `x = np.array([10 ** x for x in range(-20, 0)])`; `plt.gca().set_xticks(np.concatenate([x[:-1], x[:-1] * 3]), minor=True)` – JohanC Apr 01 '20 at 23:00
  • this doesn't resolve the issue of having major, labelled ticks at every other decade but minor, unlabelled ticks the intermediate decades – user1451632 Apr 02 '20 at 18:34
  • Well, you didn't ask for *"having major, labelled ticks at every other decade but minor, unlabelled ticks the intermediate decades"*. For that case, you could try `plt.gca().set_xticks([x[:-1:2], minor=False)`; `plt.gca().set_xticks([x[1:-1:2], minor=True)`. Maybe you could edit your question and give an explicit example of the desired ticks? – JohanC Apr 02 '20 at 18:40
  • thanks for the feedback (and the helpful answer) -- I tried to edit appropriately – user1451632 Apr 03 '20 at 14:14
  • You might want to investigate [LogLocator](https://matplotlib.org/api/ticker_api.html#matplotlib.ticker.LogLocator) and [LogFormatter](https://matplotlib.org/3.1.1/api/ticker_api.html#matplotlib.ticker.LogFormatter) (with its variants). [Example use](https://matplotlib.org/3.1.1/gallery/ticks_and_spines/tick-locators.html). – JohanC Apr 03 '20 at 14:59

0 Answers0