Created
September 29, 2020 07:32
-
-
Save yuyasugano/8a0a063b2146abec079bbcc41b1f14fc to your computer and use it in GitHub Desktop.
A trend line sample in matplotlib Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# draw the closing price and related trendlines (uptrend and downtrend) | |
fig, ax1 = plt.subplots(figsize=(15,10)) | |
color = 'tab:green' | |
xdate = [x.date() for x in df.index] | |
ax1.set_xlabel('Date', color=color) | |
ax1.plot(xdate, df.Close, label="close", color=color) | |
ax1.tick_params(axis='x', labelcolor=color) | |
ax1.legend() | |
ax2 = ax1.twiny() # ax2 and ax1 will have common y axis and different x axis, twiny | |
ax2.plot(df.Number, df.Uptrend, label="uptrend") | |
ax2.plot(df.Number, df.Downtrend, label="downtrend") | |
plt.legend() | |
plt.grid() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment