Adjusting Axis in Matplotlib

浪子不回头ぞ 提交于 2020-01-06 04:27:09

问题


When creating my graph using Matplotlib, I have coded it to automatically size the axis as follows:

plt.axis([(int(yearofreleaselist[oldestfilm])-1), (int(yearofreleaselist[0]))+1, 0, (max(profits))+50000000])

However, dealing with large figures, the profits only displays a single digit with various shorthand references, as seen on this example graph:

The year of release also doesn't plot correctly, but some results are displayed properly, as seen here:

I'm wondering how to fix this so the numbers are displayed correctly all the time.


回答1:


You can disable the offset (see documentation)

import numpy as np
import pylab as pl

years = np.arange(2011,2016,1)
profit = np.random.random(years.size)

pl.figure()
ax=pl.subplot(121)
pl.scatter(years, profit)
ax=pl.subplot(122)
pl.scatter(years, profit)
ax.get_xaxis().get_major_formatter().set_useOffset(False)

Or, to set it for all figures/axes:

import matplotlib as mpl
mpl.rcParams['axes.formatter.useoffset'] = False


来源:https://stackoverflow.com/questions/33799915/adjusting-axis-in-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!