Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Time type1 type2 type3
- 0 2015-01-01 100 200 300
- 1 2015-02-01 150 250 350
- 2 2015-03-01 300 300 300
- 3 2015-04-01 350 350 350
- #Setting up data
- import seaborn as sns
- import pandas as pd
- data = [{'Time': '201501','type1': 100, 'type2': 200, 'type3':300},
- {'Time': '201502' ,'type1':150, 'type2': 250, 'type3': 350},
- {'Time': '201503' ,'type1':300, 'type2': 300, 'type3': 300},
- {'Time': '201504' ,'type1':350, 'type2': 350, 'type3': 350}]
- data = pd.DataFrame(data)
- #Data prep
- #setting index
- data['Time']=pd.to_datetime(data['Time'], format='%Y%m')
- data.set_index(['Time'], inplace=True)
- #setting type for line graph
- data=data.astype(float)
- data
- ############################# LINE PLOT ##################################################
- #this loops over each column in my data set and produces a graph
- for i in data: # Loop over all columns except 'Location'
- sns.set() #defaults the background
- fig, ax = plt.subplots()
- sns.set(style="ticks")
- sns.lineplot(x=data.index,y=i,data=data,color=next(palette)) # column is chosen here
- sns.despine(offset=10, trim=True)
- fig.set_size_inches(18,12)
- ax.set_title('{} History'.format(i), fontweight='bold')
- plt.savefig('{}.pdf'.format(i), bbox_inches='tight') #sets file name based on column name
- ############################# VIOLIN PLOT ###############################################
- for i in data: # Loop over all columns
- sns.set() #defaults the background
- fig, ax = plt.subplots()
- sns.set(style="ticks") #darkens grid lines
- sns.violinplot(y=i, data=data,color=next(palette)) #sets which coloumn to use
- sns.despine(offset=10, trim=True)
- fig.set_size_inches(18,12)
- ax.set_title('{} Violin Plot'.format(i), fontweight='bold') #sets chart title based on column
- plt.savefig('{}_violin.pdf'.format(i), bbox_inches='tight') #sets file name based on column name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement