2014-11-05 370 views
1

我想绘制一个图表,其中x轴值= [151383,151433,175367,178368,183937] 对应的y轴值= [98,96,95,100,90]更改x轴的刻度

X轴值不是固定的间隔。但是我希望X轴应该是有规律的间隔。 如果我只写

matplotlib.pyplot(y) 

则间隔是规则的和x轴正值[1,2,3,4,5] 如何更改该实际的x轴的值?

+0

你不能只是情节(x,y)? – Anzel 2014-11-05 09:17:42

回答

1

我想这是你在找什么:

>>> from matplotlib import pyplot as plt 
>>> xval=[151383,151433,175367,178368,183937] 
>>> y=[98, 96, 95, 100, 90] 
>>> x=range(len(xval)) 
>>> plt.xticks(x,xval) 
>>> plt.plot(x,y) 
>>> plt.show() 

enter image description here

+0

你已经错过了'plot' – Anzel 2014-11-05 09:20:49

+0

号151383和151433接近,但其余的都是远...我希望在每个值之间应该有相同的间距 – 2014-11-05 09:24:30

+0

,因为如果x轴变化像= [151388,151390,151400,151899,181004],那么前4个点将太靠近,看到任何可见的差异。实际上X轴是运行编号,所以它应该在相同的空间。我得到了从其他服务器生成的运行号(ID) – 2014-11-05 09:27:28

0

用(X,Y)和x轴只是情节与定期的实际值,如果这就是你在问什么?

matplotlib.pyplot.plot(x, y) # with the plot by the way 
+0

第151383号和第151433号近在咫尺,但其余的都很远......我希望每个值之间应该有相同的间距。因为如果x轴的变化类似于[151388,151390,151400,151899,181004],那么前4个点将太靠近并且看到任何可见的差异。实际上X轴是运行编号,所以它应该在相同的空间。我从一些其他服务器生成的运行号(ID) – 2014-11-05 09:29:38

+0

@AlankritaGupta,所以你希望有规律的时间间隔点之间的可见差距? – Anzel 2014-11-05 09:31:56

+0

是..怎么一回事,因为在未来的我的x值也变得像[151388,151389,151400,20003948,18479494] – 2014-11-05 09:35:01

0

约做这样的事情是什么? (这是保罗伊万诺夫的例子)

import matplotlib.pylab as plt 
import numpy as np 

# If you're not familiar with np.r_, don't worry too much about this. It's just 
# a series with points from 0 to 1 spaced at 0.1, and 9 to 10 with the same spacing. 
x = np.r_[0:1:0.1, 9:10:0.1] 
y = np.sin(x) 

fig,(ax,ax2) = plt.subplots(1, 2, sharey=True) 

# plot the same data on both axes 
ax.plot(x, y, 'bo') 
ax2.plot(x, y, 'bo') 

# zoom-in/limit the view to different portions of the data 
ax.set_xlim(0,1) # most of the data 
ax2.set_xlim(9,10) # outliers only 

# hide the spines between ax and ax2 
ax.spines['right'].set_visible(False) 
ax2.spines['left'].set_visible(False) 
ax.yaxis.tick_left() 
ax.tick_params(labeltop='off') # don't put tick labels at the top 
ax2.yaxis.tick_right() 

# Make the spacing between the two axes a bit smaller 
plt.subplots_adjust(wspace=0.15) 

plt.show() 
+0

第151383号和151433号近在咫尺,但其余的都很远......我希望每个值之间应该有相同的间距。 – 2014-11-05 10:26:04

+0

我更新了我原来的帖子,以反映我相信你想要做的事。 – eivl 2014-11-05 11:58:31

+0

这导致了图中的2个子图。其中一个来自(0,1),另一个来自(9,10)...它是不是psbl在单个情节? – 2014-11-05 12:37:13