在x轴大熊猫上显示的范围内选择特定数量的值

时间:2018-08-03 10:07:27

标签: python pandas matplotlib

我想在x轴上绘制一个带有时间的度量图,但在该图中,我只希望在轴上显示20个代表性等距值(但我希望污点已使用所有数据)。 我的代码是上面显示的代码:

### imports ###
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import math
from datetime import datetime
import time
### end of imports ###

data=pd.read_csv('copy_prmon.txt',sep='\s+') # returns the dataframe object data

### convert time format and make time starting from zero ###
s=data.iloc[:,0] #select first column of data frame
data['Time']=s-s.iloc[0] # Time = Time - Time[0]
data['Time'] = pd.to_datetime(data['Time'],unit='s') #convert to readable time
data['Time']=data.Time.dt.time #show only time part and not date
### end of converting time ###

data #show data

### changing the size of the canvas ###
fig_size = plt.rcParams["figure.figsize"]
print "Current size:", fig_size
fig_size[0] = 12
fig_size[1] = 9
plt.rcParams["figure.figsize"] = fig_size
### end of changing the size of canvas ###

#mt=data['Time'].diff().cumsum() 
data['Time'] = data['Time'].astype('|S') #convert time from object to string
plt.plot(data['Time'],data['rx_packets'],color="green") #plot
plt.gcf().autofmt_xdate() 
plt.locator_params(axis='x',nbins=20)

### name axis and plot ###
plt.xlabel("Time",color="green")
plt.ylabel("rx_packets",color="green")
plt.title("PLOT OF A METRIC (rx_packets)",color="green")
### end of name axis and plot ###

plt.show() #show the plot

剧情是上面的情节

plot

在此图中显示了前20个刻度。我该如何更改,以便在“时间”的数据范围内等距20个滴答声? 第一个时间数据是00:00:00,最后一个时间是02:18:59,具有第31步(270个值)。

0 个答案:

没有答案