我有以下范围的numpy数据(usec时间戳的增量):
array([ 4.312, 4.317, 4.316, 4.32 , 4.316, 4.316, 4.319, 4.317,
4.317, 4.316, 4.318, 4.316, 4.318, 4.316, 4.318, 4.317,
4.317, 4.317, 4.316, 4.317, 4.318, 4.316, 4.318, 4.316,
4.318, 4.316, 4.317, 4.317, 4.318, 4.316, 4.317, 4.317,
4.317, 4.317, 4.317, 4.316, 4.319, 4.315, 4.319, 4.315,
4.319, 4.315, 4.316, 4.319, 4.317, 4.317, 4.317, 4.318,
4.315, 4.317, 4.317, 4.317, 4.319, 4.314, 4.32 , 4.315,
4.317, 4.318, 4.315, 4.318, 4.317, 4.317, 4.317, 4.316,
4.317, 4.318, 4.317, 4.317, 4.317, 4.315, 4.319, 4.317,
4.315, 4.319, 4.316, 4.318, …
Run Code Online (Sandbox Code Playgroud) 我在这里提供了其他问题
plt.gca().get_xaxis().get_major_formatter().set_useOffset(False)
Run Code Online (Sandbox Code Playgroud)
作为一种消除当前图上轴偏移的方法,但默认情况下有没有办法做到这一点?我在matplotlibrc文件中看不到任何看似有用的内容.
I've created a simple hexbin plot with matplotlib.pyplot. I haven't changed any default settings. My x-axis information ranges from 2003 to 2009, while the y values range from 15 to 35. Rather than writing out 2003, 2004, etc., matplotlib collapses it into 0, 1, 2, ... + 2.003e+03. Is there a simple way to force matplotlib to write out the full numbers?
Thanks,
Mark C.
我试图imshow
使用以下代码更改x轴上的刻度值:
import matplotlib.pyplot as plt
import numpy as np
def scale_xaxis(number):
return(number+1001)
data = np.array([range(10),range(10,20)])
fig = plt.figure(figsize=(3,5))
ax = fig.add_subplot(111)
ax.imshow(data,aspect='auto')
ax.autoscale(False)
xticks = ax.get_xticks()
ax.xaxis.set_ticklabels(scale_xaxis(xticks))
plt.savefig("test.png")
Run Code Online (Sandbox Code Playgroud)
得到的图像http://ubuntuone.com/2Y5ujtlEkEnrlTcVUxvWLU
然而,x-ticks重叠并具有"非圆形"值.matplotlib有什么方法可以自动执行此操作吗?通过使用set_ticklabels
或其他方式?
我花了一些时间徒劳地寻找我的问题的答案,所以我认为一个新的问题是有序的.考虑这个情节:
轴标签使用科学记数法.在y轴上,一切都很好.但是,我已经尝试并且未能摆脱Python在右下角添加的缩放因子.我想要完全删除这个因素,只需通过轴标题中的单位指示它,或者将它乘以每个刻度标签.一切都看起来比这丑陋1e14
.
这是代码:
import numpy as np data_a = np.loadtxt('exercise_2a.txt')
import matplotlib as mpl
font = {'family' : 'serif',
'size' : 12}
mpl.rc('font', **font)
import matplotlib.pyplot as plt
fig = plt.figure()
subplot = fig.add_subplot(1,1,1)
subplot.plot(data_a[:,0], data_a[:,1], label='$T(t)$', linewidth=2)
subplot.set_yscale('log')
subplot.set_xlabel("$t[10^{14}s]$",fontsize=14)
subplot.set_ylabel("$T\,[K]$",fontsize=14)
plt.xlim(right=max(data_a [:,0]))
plt.legend(loc='upper right')
plt.savefig('T(t).pdf', bbox_inches='tight')
Run Code Online (Sandbox Code Playgroud)
更新:将Will的实现结合scientificNotation
到我的脚本中,情节现在看起来像
如果你问我,好多了.对于想要采用其中某些部分的人来说,这是完整的代码:
import numpy as np
data = np.loadtxt('file.txt')
import matplotlib as mpl
font = {'family' : 'serif',
'size' : 16}
mpl.rc('font', **font)
import matplotlib.pyplot as plt
fig = …
Run Code Online (Sandbox Code Playgroud) 我在编辑作品时注意到了这种细微差别.
以前,matplotlib看起来像这样:
x=[1,2,3,4,5]
y=[4,5,5,2,1]
plot(x,y,'-')
Run Code Online (Sandbox Code Playgroud)
但是在最近的升级之后我相信,有偏差,这将会像这样回归
这与我现在看到的有点不相干.我想知道
如果这种偏移是数据可视化的一个很好的实践?如果是这样,我会保持原样.
如何取消这个偏移量?
我可以手动恢复限制plt.gca().set_xlim([1, 5])
,但如果我有另外20个图,则无法扩展.我用Google搜索并没有找到太多关于此的信息.