My x axis labels are
0.00 0.01 0.02 0.03
etc. How can I format it as:
0 0.01 0.02 0.03
well I tried those:
plt.xlim([0,0.03])
plt.xticks(np.arange(0, 0.03, 0.01))
neither does work. I think this should be fixed, 0.00 is meaningless.
My x axis labels are
0.00 0.01 0.02 0.03
etc. How can I format it as:
0 0.01 0.02 0.03
well I tried those:
plt.xlim([0,0.03])
plt.xticks(np.arange(0, 0.03, 0.01))
neither does work. I think this should be fixed, 0.00 is meaningless.
You could use a custom formatter for your x-axes that prints integers as such:
from matplotlib.ticker import FuncFormatter
def my_formatter(x, pos):
if x.is_integer():
return str(int(x))
else:
return str(x)
formatter = FuncFormatter(my_formatter)
fig, ax = plt.subplots()
ax.xaxis.set_major_formatter(formatter)
plt.show()
Have you used plt.yticks([0, 0.01, 0.02, 0.03], ['0', '0.01', '0.0.2', '0.03'])
?
To change a specific tick, you could either use a custom formatter, or something like the following:
import matplotlib.pyplot as plt
plt.plot([1,3,2])
plt.draw() # Note, this line is important
ax = plt.gca() # and you don't need this line if you already have an axis handle somewhere
labels = [l.get_text() for l in ax.get_xticklabels()]
labels[0] = '0'
ax.set_xticklabels(labels)
plt.show()