调整Matplotlib中的轴 [英] Adjusting Axis in Matplotlib
问题描述
使用Matplotlib创建我的图时,我已经编码它来自动调整轴的大小,如下所示:
plt.axis [(int(yearofreleaselist [oldestfilm]) - 1),(int(yearofreleaselist [0]))+ 1,0(max(profits))+ 50000000])
pre>
然而,在处理大数字时,利润只显示一个数字,并带有各种速记引用,如此示例图所示:
发布年份也没有正确显示,但是一些结果显示正确,如下所示:
imgur.com/cUXEK.pngalt =看到这里>
我想知道如何解决这个问题,所以数字一直显示正确。 / p>
解决方案您可以禁用偏移量(
或者,为所有数字/坐标轴设置:
import matplotlib as mpl
mpl.rcParams ['axes.formatter.useoffset'] = False
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.
解决方案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
这篇关于调整Matplotlib中的轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!