2017-04-08 28 views
3

所以我一直在SE上搜索一段時間,沒有找到任何工作.....我有一個多年來的最低和最高溫度的數據幀。如何更改滴答數量?

plt.figure() 
plt.gca().fill_between(range(len(Tmin)), Tmin, Tmax, facecolor='blue', alpha=0.25) 
plt.plot(range(365), Tmin, 'b', range(365), Tmax, 'r') 
plt.locator_params(axis = 'x', nbins = 12) 

x = plt.gca().xaxis 
m = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'] 
ax = plt.gca() 
ax.locator_params(axis = 'x', nbins = 12) 
ax.set_xticklabels(m) 
ax.set_ylabel('T(C)') 
ax.set_title('Temperature') 
plt.xlim([0,365]) 
# ax.set_xticks(np.linspace(0,1,12)) 
plt.show() 

它仍然相同數目的滴答輸出作爲原始情節,其中x軸是[0,50,100,...,350]

enter image description here

回答

2

你可以通過獲取自1月1日以來每個月的日子來手動設置標記。

import datetime as dt 
import numpy as np 
import matplotlib.pyplot as plt 

x = np.arange(365) 
y = 100 + 250*np.sin(9*(x-50)/720) + 80*np.random.rand(365) 

m = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'] 
# get the start day for each month as an index 
ticks = [(dt.date(2016,m,1)-d0).days for m in range(1,13)] 

fig,ax = plt.subplots(1,1) 
ax.plot(x,y) 
ax.set_xticks(ticks) 
ax.set_xticklabels(m) 
ax.set_xlim(-3,365) 
plt.show() 

enter image description here

+0

不錯!謝謝:)你會碰巧也知道爲什麼我不能移動我的傳奇任何機會? : Raksha