Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

seasonal plot python time series

# Import Data
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/a10.csv', parse_dates=['date'], index_col='date')
df.reset_index(inplace=True)

# Prepare data
df['year'] = [d.year for d in df.date]
df['month'] = [d.strftime('%b') for d in df.date]
years = df['year'].unique()

# Prep Colors
np.random.seed(100)
mycolors = np.random.choice(list(mpl.colors.XKCD_COLORS.keys()), len(years), replace=False)

# Draw Plot
plt.figure(figsize=(16,12), dpi= 80)
for i, y in enumerate(years):
    if i > 0:        
        plt.plot('month', 'value', data=df.loc[df.year==y, :], color=mycolors[i], label=y)
        plt.text(df.loc[df.year==y, :].shape[0]-.9, df.loc[df.year==y, 'value'][-1:].values[0], y, fontsize=12, color=mycolors[i])

# Decoration
plt.gca().set(xlim=(-0.3, 11), ylim=(2, 30), ylabel='$Drug Sales$', xlabel='$Month$')
plt.yticks(fontsize=12, alpha=.7)
plt.title("Seasonal Plot of Drug Sales Time Series", fontsize=20)
plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: no definition 
Python :: how to murj record in django 
Python :: display colors in python console 
Python :: python read file with class 
Python :: find duplicate row in python sqlite database 
Python :: data framing with Pandas 
Python :: Python NumPy asfarray Function Syntax 
Python :: Python NumPy require Function Syntax 
Python :: Python NumPy row_stack Function Syntax 
Python :: percentile of a score python 
Python :: Python NumPy dsplit Function Syntax 
Python :: (ax=self.canv.axes ,style="ro--") 
Python :: Python __sub__ magic method 
Python :: pyqt log widget thread safe 
Python :: else clause in for loop python 
Python :: NumPy bitwise_xor Code When inputs are numbers 
Python :: django view - Generic class based view (listc, create, retrieve, update or delete - GET, POST, GET, PUT, DELETE) 
Python :: # convert dictionary keys to a list 
Python :: how to show all rows whith a unique value in a column 
Python :: Double all numbers using a map() and Lamda Function 
Python :: cv2 recize 
Python :: List change after copy Python 
Python :: pandas groupby min get index 
Python :: how do i add two matrix and store it in a list in python 
Python :: app.callback output is not defined 
Python :: cyclic rotation python 
Python :: perform cross tabulation sklearn 
Python :: plt datas use left and right yaxes 
Python :: ring Desktop, WebAssembly and Mobile create an application to ask the user about his/her name. 
Python :: Problems with flask bootstrap 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =