简体   繁体   中英

Matplotlib changing axis ticks

I have a few lines of making a scatter plot out of a collection of points (x 0 ,y 0 ), ... (x n ,y n ).

The truth is that I am only interested in the x scale as it is the scale on which the graph is power law behaved but after plotting I would like to replace the ticks on the x-axis by some other function of $x_i$ .

How could I do so?

You can tell matplotlib where to put the x-axis labels by

ax.set_xticks(positions)

where positions is a list of tick positions in the scale which your data is using for x-positioning and ax is the axis to plot on ( ax=plt.gca() or ax=fig.gca() ). You can then set the tick labels:

ax.set_xticklabels(labels)

Example: you want to display x-ticks in log scale but still use a linear scale for the x-axis (not very useful, I know):

positions = np.array([1, 10, 100, 1000])
ax.set_xticks(positions)
ax.set_xticklabels(np.log10(positions))

Note however, that this won't change the x-scale of your data!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM