0
(Windows用のPython 3.5 x64を使用)Python Matplotlib pyplot - x軸の値がデータに適合しない
こんにちは!
Imは、特定のUNIX時間に整数の形式でデータを使用しています。 私はx軸(unix時間)を「最初のレコードからの秒数」にしたいが、この軸の値はこれに適合しないという問題があります。つまり、y軸の最初の整数はx軸の0の値に設定されていません。 私のニーズに合わせてx軸の値を変更するにはどうすればよいですか? 私はすでにいくつかのことを試みました:xticks、axes.set_ylim()...しかし、私は決して解決できない問題に直面しました。 pythonへ
def plot_overview2(selector = None):
global logtime, logtime_delta, cpm, color
plt.figure(figsize=(14,7), dpi=70, facecolor="none") #was figsize=(20,10),dpi=70,facecolor="none" - filled whole screen
plt.suptitle('CPM ', fontsize=16, fontweight='bold')
plt.subplots_adjust(hspace=None, wspace=.2, left=.05, top=.95, bottom=.07, right=.98)
plt.subplot(1, 1, 1)
plt.grid(True)
# add a label to the x and y axis
plt.xlabel('Time since first record [sec]')
plt.ylabel("CPM")
# define the x-axis limits
xmin = logtime.min() # e.g. 1483049960.0
xmax = logtime.max() # e.g. 1483295877.0
plt.xlim(xmin, xmax) # if commented out then the plot will find its own limits
#plt.xticks(1, logtime_delta)
# define the y-axis limits
#plt.ylim(0, 150) # if commented out then the plot will find its own limits
recmax = cpm.size # allows to limit the data range plotted
# plot the raw data
plt.plot(logtime[:recmax],cpm[:recmax], color=color['cpm'], linewidth=.75, label ="") #linewidth was .5, logtime[:recmax],cpm[:recmax]
#plt.plot_date(logtime, cpm, color=color['cpm'], linewidth=.75, label ="")
# plot the moving average over N datapoints with red on yellow line background
# skip the first and last N/2 data points, which are meaningless due to averaging
if len(logtime) < 300:
N=len(logtime)+1/2
else:
N=300
plt.plot(logtime[N//2:recmax - N//2], np.convolve(cpm, np.ones((N,))/N, mode='same')[N//2:recmax - N//2], color="yellow", linewidth=6, label ="")
plt.plot(logtime[N//2:recmax - N//2], np.convolve(cpm, np.ones((N,))/N, mode='same')[N//2:recmax - N//2], color="red", linewidth=2, label ="MovAvg, N="+str(N))
# plot the line for the average
av = np.empty(recmax)
npav = np.average(cpm[:recmax])
av[:] = npav
plt.plot(logtime[:recmax], av[:recmax], color=color['MW'], linewidth=2, label= "Average CPM={0:6.3f}".format(npav))
# plot the legend in the upper left corner
plt.legend(bbox_to_anchor=(1.01, .9), loc=2, borderaxespad=0.)
plt.legend(loc='upper left')
Imは本当に新しい... xticksは仕事ができる、しかし、私はCPMと時間との相関関係が失われないように、という点で、UNIX時間に合わせて方法を知ってはいけません。それで簡単な答えをお願いします。 :) ありがとう!プロットのすべてのための
plot(logtime[N//2:recmax - N//2] - logtime[0], ...
:
まずラインをプロットは、ほぼ20000
これはうまくいきましたが、驚くほど簡単でした... xDありがとう! – Distelzombie
問題はありません:)答えを受け入れることができますか? –