Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. ax = plt.gca()
  3.  
  4. # d is a dictionary from which dataframe is constructed
  5. df = pd.DataFrame(data=d)
  6.  
  7. # to_plot (a function argument) is a dictionary of boolean values to decide what to plot, e.g.
  8. to_plot = {'A':True,
  9. 'B':True,
  10. 'C':False,
  11. 'D':True}
  12.  
  13. if to_plot['A']:
  14. pl = df['A'].plot(kind='bar', xticks=df.index, title=storage, ax=ax, color='deepskyblue', legend=True)
  15.  
  16. if to_plot['B']:
  17. pl = df['B'].plot(drawstyle='steps-post', xticks=df.index, title=storage, color='lightgreen',
  18. linewidth=3, ax=ax, legend = True)
  19. if to_plot['C']:
  20. pl = df['C'].plot(drawstyle='steps-post', xticks=df.index, title=storage, color='green',
  21. linestyle='--', linewidth=2, ax=ax, legend=True)
  22. if to_plot['D']:
  23. pl = df['D'].plot(drawstyle='steps-post', xticks=df.index, title=storage, color='orange',
  24. linewidth=3, ax=ax, legend=True)
  25.  
  26. if to_plot['A'] or to_plot['B'] or to_plot['C'] or to_plot['D'] :
  27. plt.legend(loc='best')
  28. pl.set_xlabel("Time")
  29. pl.set_ylabel("Storage state(in %)")
  30. plt.show()
  31.  
  32. fig = plt.figure()
  33. ax = fig.add_axes([0.1, 0.1, 1, 1])
  34.  
  35. UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
  36. MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
  37. ax=fig.add_axes([0.1,0.1,1,1])
  38. WARNING:matplotlib.legend:No handles with labels found to put in legend.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement