简体   繁体   English

Python - 你怎么能 plot 数据直方图?

[英]Python - How can you plot a data histogram?

I am looking to plot a date histogram.我正在寻找 plot 日期直方图。 I have a pandas dataframe as follow:我有一个 pandas dataframe 如下:

Creation Date  Profile_ID Count
2016-06-01            150
2016-06-03            3
2016-06-04            20 

How can I define the x and y axis of my histogram so that I have a plot of the number of newly-created profile ID per date?如何定义我的直方图的 x 和 y 轴,以便我有一个 plot 每个日期新创建的配置文件 ID 的数量?

Try:尝试:

import matplotlib.pyplot as plt
ax = df.plot.bar(y='Profile_ID Count')
plt.show()
# Importing the requisite libraries
import pandas as pd
import matplotlib.pyplot as plt

# Creating the DataFrame
df = pd.DataFrame({'Creation Date':['2016-06-01','2016-06-03','2016-06-04'],'Profile_ID Count':[150,3,20]})

# Creating the bar chart below.
fig, ax = plt.subplots()
ax.bar(df['Creation Date'],df['Profile_ID Count'], color='red', width = 0.5)   
fig.autofmt_xdate()   # This tilts the dates displayed along X-axis.
ax.set_title('Creation Date vs. Profile ID Count')
ax.set_xlabel('Creation Date')
ax.set_ylabel('Profile ID Count')
plt.show()

条形图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM