[英]how to adjust x axis in matplotlib
I have a graph like this 我有一个这样的图
The data on the x axis means hours, so I want the x axis to set as 0, 24, 48, 72.....instead of the value now, which is difficult to see the data between [0,100] x轴上的数据表示小时,因此我希望x轴设置为0、24、48、72 .....而不是现在的值,这很难看到[0,100]之间的数据
fig1 = plt.figure()
ax = fig1.add_subplot(111)
ax.set_yscale('log')
ax.plot(x,y,'b-')
According to the the first answer, I got this: 根据第一个答案,我得到了:
It sounds like you want to changes the limits of the plotting display - for that use xlim
(and ylim
for the other axis). 这听起来像你想改变绘图显示的限制-对于使用
xlim
(和ylim
为其他轴)。 To change the xticks themselves is provided in the answer by @fp. @fp的答案中提供了更改xticks本身的方法。 Show below is an example using without/with
xlim
: 下面显示的是使用不带
xlim
:
# Sample data
import numpy as np
N = 2000
X = np.random.gamma(.5,size=N)*100
import pylab as plt
plt.subplot(2,1,1)
plt.hist(X,bins=300)
plt.subplot(2,1,2)
plt.hist(X,bins=300)
plt.xlim(0,100)
plt.show()
The size of the plot can be changed by setting the dynamic rc settings of Matplotlib. 可以通过设置Matplotlib的动态rc设置来更改图的大小。 These are stored in a dictionary named rcParams.
这些存储在名为rcParams的字典中。 The size of the plot figure is stored with the key figure.figsize.
图的大小与key Figure.figsize一起存储。
As an example, to get and set the size of a Matplotlib plot: import matplotlib.pyplot as plt 例如,获取并设置Matplotlib图的大小:import matplotlib.pyplot as plt
fig_size = plt.rcParams["figure.figsize"] #Get current size
print "Current size:", fig_size #Prints: [8.0, 6.0]
fig_size[0] = 12 #Set figure width to 12 and height to 9
fig_size[1] = 9
plt.rcParams["figure.figsize"] = fig_size
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.