Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tested in:
- # Python 3.6.13 :: Anaconda, Inc.
- # matplotlib==3.3.4
- # pandas==1.1.5
- import matplotlib.pyplot as plt
- import numpy as np
- from datetime import timedelta, datetime
- import pandas as pd
- # generate dummy data
- dummy_closed = np.random.randint(-100, 101, 10000).cumsum()
- stock = pd.DataFrame(dummy_closed, columns=["Close"], index = reversed([datetime.now() - timedelta(days = 1) * i for i in range(10000)]))
- fig = plt.figure()
- ax = fig.add_subplot(111)
- # same as ax.plot(stock["Close"])
- stock["Close"].plot(ax = ax)
- ax.fill_between(
- stock.index,
- min(stock["Close"]),
- max(stock["Close"]), # or using stock["Close"] to draw area under curve
- where = stock.index >= "2020-01-01",
- alpha = 0.5,
- )
- # Important, render the xticks before using get_xticklabels
- fig.tight_layout()
- for l in ax.get_xticklabels():
- # set xticklabel align to center
- l.set_horizontalalignment("center")
- fig.tight_layout()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement