Advertisement
Guest User

#1Z7dnzO1 (Python)

a guest
Sep 12th, 2022
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. # tested in:
  2. # Python 3.6.13 :: Anaconda, Inc.
  3. # matplotlib==3.3.4
  4. # pandas==1.1.5
  5.  
  6. import matplotlib.pyplot as plt
  7. import numpy as np
  8. from datetime import timedelta, datetime
  9. import pandas as pd
  10.  
  11.  
  12. # generate dummy data
  13. dummy_closed = np.random.randint(-100, 101, 10000).cumsum()
  14. stock = pd.DataFrame(dummy_closed, columns=["Close"], index = reversed([datetime.now() - timedelta(days = 1) * i for i in range(10000)]))
  15.  
  16.  
  17.  
  18. fig = plt.figure()
  19. ax = fig.add_subplot(111)
  20.  
  21. # same as ax.plot(stock["Close"])
  22. stock["Close"].plot(ax = ax)
  23. ax.fill_between(
  24.     stock.index,
  25.     min(stock["Close"]),
  26.     max(stock["Close"]), # or using stock["Close"] to draw area under curve
  27.     where = stock.index >= "2020-01-01",
  28.     alpha = 0.5,
  29. )
  30. # Important, render the xticks before using get_xticklabels
  31. fig.tight_layout()
  32. for l in ax.get_xticklabels():
  33.     # set xticklabel align to center
  34.     l.set_horizontalalignment("center")
  35. fig.tight_layout()
  36. plt.show()
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement