(Использование Python 3.5 x64 для окон)Python Matplotlib pyplot - оси х значения неподходящие для данных
Привет!
Im, используя данные в формате целого числа в определенное время unix. У меня проблема, когда я хочу, чтобы ось x (время unix) была «временем с первой записи в секундах», но значения этой оси не соответствуют этому. Я имею в виду: первое целое число от оси y не задано при значении 0 оси x. Как изменить значения оси x в соответствии с моими потребностями? Я уже несколько раз пробовал: xticks, axes.set_ylim() ... но всегда сталкивался с проблемой, которую я не мог решить. xticks может работать, но я не знаю, как, чтобы соответствовать времени UNIX в том, что так, что корреляция между имп и времени не потерялась ...
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 действительно нового питона. Так что, пожалуйста, дайте легкие ответы. :) Спасибо!
Первый график линии начинается почти 20000
Хорошо, что сработало и было удивительно просто ... xD Спасибо! – Distelzombie
Без проблем :) не могли бы вы принять ответ? –