furas

Python - plot only some labels

Jun 27th, 2018
98
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3.  
  4. headers = 'Date', 'Close', 'Open', 'High', 'Low'
  5.  
  6. text = '''27/12/2012 4541,79 4560,12 4560,75 4534,55
  7. 28/12/2012 4561,98 4541,79 4561,99 4536,47
  8. 31/12/2012 4579,85 4559,31 4579,85 4558,51
  9. 02/01/2013 4621,99 4588,08 4621,99 4586,71
  10. 03/01/2013 4642,08 4643,92 4654,52 4621,81
  11. 04/01/2013 4654,33 4648,85 4677,97 4642,69
  12. 07/01/2013 4652,74 4651,63 4663,86 4632,11'''.replace(',', '.')
  13.  
  14. # --- create data ---
  15.  
  16. data = [line.split() for line in text.split('\n')]
  17.  
  18. df = pd.DataFrame(data, columns=headers)    
  19. df['Close'] = df['Close'].astype(float)
  20.  
  21. # --- plot ---
  22.  
  23. ax = plt.plot(df['Close'], df['Date'])
  24. ax[0].axes.set_yticks(df['Date'][::2]) # skip every 2nd label
  25.  
  26. #ax[0].axes.set_yticklabels(df['Date'][::2])
  27.  
  28. plt.show()
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×