Plotting x-axis in log scale spacing but not labeling it in exponential form
Question:
I would like to plot say two values x = [0, 10,20,50,100]
and y=[1,2,3,10,100]
using pylab. I want to keep the spacing of x-axis in log form. But I want to tick at the values of x i’e at 10, 20, 50, 100 and print them as it not in the form of 10e1 or 10e2. I am doing it as follows:
import matplotlib.pylab as plt
plt.xscale('log')
plt.plot(x, y)
plt.xticks(x)
plt.grid()
But it keeps the values in the form of 10e1, 10e2.
Could you please help me out?
Answers:
I think what you want is to change the major_formatter
of the x axis?
import matplotlib.pylab as plt
import numpy as np
from matplotlib.ticker import ScalarFormatter
x = [0, 10,20,50,100]
y=[1,2,3,10,100]
plt.plot(x, y)
plt.xscale('log')
plt.grid()
ax = plt.gca()
ax.set_xticks(x[1:]) # note that with a log axis, you can't have x = 0 so that value isn't plotted.
ax.xaxis.set_major_formatter(ScalarFormatter())
plt.show()
I would like to plot say two values x = [0, 10,20,50,100]
and y=[1,2,3,10,100]
using pylab. I want to keep the spacing of x-axis in log form. But I want to tick at the values of x i’e at 10, 20, 50, 100 and print them as it not in the form of 10e1 or 10e2. I am doing it as follows:
import matplotlib.pylab as plt
plt.xscale('log')
plt.plot(x, y)
plt.xticks(x)
plt.grid()
But it keeps the values in the form of 10e1, 10e2.
Could you please help me out?
I think what you want is to change the major_formatter
of the x axis?
import matplotlib.pylab as plt
import numpy as np
from matplotlib.ticker import ScalarFormatter
x = [0, 10,20,50,100]
y=[1,2,3,10,100]
plt.plot(x, y)
plt.xscale('log')
plt.grid()
ax = plt.gca()
ax.set_xticks(x[1:]) # note that with a log axis, you can't have x = 0 so that value isn't plotted.
ax.xaxis.set_major_formatter(ScalarFormatter())
plt.show()