Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. Time type1 type2 type3
  2. 0 2015-01-01 100 200 300
  3. 1 2015-02-01 150 250 350
  4. 2 2015-03-01 300 300 300
  5. 3 2015-04-01 350 350 350
  6.  
  7. #Setting up data
  8. import seaborn as sns
  9. import pandas as pd
  10.  
  11. data = [{'Time': '201501','type1': 100, 'type2': 200, 'type3':300},
  12. {'Time': '201502' ,'type1':150, 'type2': 250, 'type3': 350},
  13. {'Time': '201503' ,'type1':300, 'type2': 300, 'type3': 300},
  14. {'Time': '201504' ,'type1':350, 'type2': 350, 'type3': 350}]
  15.  
  16. data = pd.DataFrame(data)
  17.  
  18. #Data prep
  19.  
  20. #setting index
  21. data['Time']=pd.to_datetime(data['Time'], format='%Y%m')
  22. data.set_index(['Time'], inplace=True)
  23. #setting type for line graph
  24. data=data.astype(float)
  25.  
  26. data
  27.  
  28. ############################# LINE PLOT ##################################################
  29.  
  30. #this loops over each column in my data set and produces a graph
  31.  
  32. for i in data: # Loop over all columns except 'Location'
  33. sns.set() #defaults the background
  34. fig, ax = plt.subplots()
  35. sns.set(style="ticks")
  36. sns.lineplot(x=data.index,y=i,data=data,color=next(palette)) # column is chosen here
  37. sns.despine(offset=10, trim=True)
  38. fig.set_size_inches(18,12)
  39. ax.set_title('{} History'.format(i), fontweight='bold')
  40.  
  41. plt.savefig('{}.pdf'.format(i), bbox_inches='tight') #sets file name based on column name
  42.  
  43.  
  44. ############################# VIOLIN PLOT ###############################################
  45. for i in data: # Loop over all columns
  46. sns.set() #defaults the background
  47. fig, ax = plt.subplots()
  48. sns.set(style="ticks") #darkens grid lines
  49. sns.violinplot(y=i, data=data,color=next(palette)) #sets which coloumn to use
  50. sns.despine(offset=10, trim=True)
  51. fig.set_size_inches(18,12)
  52. ax.set_title('{} Violin Plot'.format(i), fontweight='bold') #sets chart title based on column
  53. 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