Reputation: 15
I have been trying to achieve something like this: Example
So far this is what I have tried:
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)
Note- on the x-axis I would like to display each year/month: 2017/08
Current output below, is not showing all months/year or any lines for the crime types Current Ouput
Upvotes: 0
Views: 3040
Reputation: 2497
Not sure how your data looks.
But python has a nice way of doing subplots:
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)
Upvotes: 2