2014-11-05 372 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