0

I made a log scale graph below.

How to show the regular ticks without scientific notation?

How to customize ticks with different format combined?

plt.plot(np.arange(1000))
plt.xscale('log')
plt.yscale('log')
plt.ylim(1,10)
plt.show()

enter image description here

kinder chen
  • 1,371
  • 5
  • 15
  • 25

1 Answers1

0

Because you said that you've tried these solutions, and they didn't work, I suspect it is because you called ax.yaxis.set_major_formatter before setting the scale to log. If you do that, it resets the x and y axes when you say plt.xscale('log') and plt.yscale('log').

If you call it after, it works:

import matplotlib as mpl
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1,1,1)

plt.plot(np.arange(1000))
plt.xscale('log')
plt.yscale('log')

ax.yaxis.set_major_formatter(mpl.ticker.ScalarFormatter())
ax.xaxis.set_major_formatter(mpl.ticker.ScalarFormatter())

plt.show()

enter image description here

sacuL
  • 49,704
  • 8
  • 81
  • 106
  • Thanks. Must I use `ax = fig.add_subplot(1,1,1)` ? Can I use `plt` directly' ? – kinder chen Aug 10 '18 at 23:04
  • You can use `plt.gca().yaxis.set_major_formatter(mpl.ticker.ScalarFormatter())` and `plt.gca().xaxis.set_major_formatter(mpl.ticker.ScalarFormatter())` if you want – sacuL Aug 10 '18 at 23:07
  • Thanks. what's the purpose to use `fig = plt.figure()` and `ax = fig.add_subplot(1,1,1)` ? To make the code neat, why not just use `plt` ? – kinder chen Aug 10 '18 at 23:10
  • It's just a way to explicitly create an axes object, sometimes it can be easier to refer to actual axes. – sacuL Aug 10 '18 at 23:12
  • Thanks. I re-editted the question and added `plt.ylim(1,10)`, now it doesn't work again. BTW, the new ticks have a decimal point, how can I get rid of it. – kinder chen Aug 10 '18 at 23:17