Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

seasonal plot python

# 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 :: else 
Python :: Django merge duplicate rows 
Python :: df create dummy from multiple category 
Python :: with statement in python 
Python :: python code to find duplicate row in sqlite database 
Python :: 123bum123 
Python :: Python NumPy asfortranarray Function Syntax 
Python :: Python NumPy require Function Example without requirements attribute 
Python :: Python NumPy column_stack Function Example with 1d array 
Python :: making dividers in tkinter 
Python :: Python NumPy hsplit Function Syntax 
Python :: python json serialize print pretty 
Python :: __div__ 
Python :: how to get defintiion of pysspark teable 
Python :: del mutiple indexes at once 
Python :: NumPy bitwise_xor Code When inputs are arrays 
Python :: django view - apiview decorator (retrieve, update or delete - GET, PUT, DELETE) 
Python :: flatten a list using numpy and itertools 
Python :: python list and numpy array 
Python :: LCS Problem Python 
Python :: lsit to dataframe 
Python :: qmenu 
Python :: groupby and add aggregated column 
Python :: update table odoo13 
Python :: python assert multiple conditions 
Python :: extracting code blocks from Markdown 
Python :: get the first principle component of pca 
Python :: how to enter tavble in sal through sql 
Python :: create schema for table for django 
Python :: py3 identify file extension 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =