绘制子图-Python

时间:2018-10-27 19:49:35

标签: python pandas numpy matplotlib datetimeindex

我一直在努力实现以下目标: Example

到目前为止,这是我尝试过的:

crimes.Month = pd.to_datetime(crimes.Month, format='%Y/%m')

crimes.index = pd.DatetimeIndex(crimes.Month)

import numpy as np

crimes_count_date = crimes.pivot_table('Month', aggfunc=np.size,columns='Crime type', index=crimes.index.date, fill_value=0)

crimes_count_date.index = pd.DatetimeIndex(crimes_count_date.index)

plo = crimes_count_date.rolling(365).sum().plot(figsize=(12, 30),subplots=True, layout=(-1, 3), sharex=False, sharey=False)

注意-我想每年/每月在x轴上显示:2017/08

下面的当前输出未显示所有月份/年份或犯罪类型的所有行 Current Ouput

1 个答案:

答案 0 :(得分:2)

不确定数据的外观。

但是python有一个很好的做子图的方法:

import matplotlib.pyplot as plt
plt.figure(figsize=(16,8)) ## setting over-all figure size (optional)
plt.subplot(2, 3, 1) 

##  this creates 6 subplots (2 rows and 3 columns)
## 1 at the end means we are in the first subplot.. then...

plt.plot(x1,y1) ## for well-selected x1 and y1
plt.subplot(232) ## the same as subplot(2, 3, 2) - you can use this when values have
                 ## one digit only; now we are in the 2nd subplot
plt.plot(x2, y2)  ## this will be plotted in the second subplot

## etc. ...

plt.subplot(236)
plt.plot(x6,y6)