-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Side-by-Side Plots #318
Comments
Hi @debjyotiarr Nice job on those plots. I have considered, in addition to kwarg However there are two workarounds: The first workaround is is to use external axes mode. The advantage of this method is that you have full control over all aspects of the plot. The main disadvantage is that you will have to write extra code if you want to line up the panels nicely as in your examples, since you will not be able to benefit from mplfinance doing that for you. (The reason mplfinance can't do that when in external axes mode is because, since the axes are passed in, mplfinance has no control over where the axes are placed on the figure. See, for example, cell The second workaround is simpler, but still involves a bit of code. The idea is to save each plot as an image, and then create a matplotlib Figure with side-by-side Axes, and display each plot image on each of the Axes. Here is a an example where, instead of writing to disk, the plots are saved in memory as BytesIO objects: import pandas as pd
import mplfinance as mpf
import matplotlib.pyplot as plt
import matplotlib.image as m_img
import io
# Read the data:
df = pd.read_csv('data/SP500_NOV2019_Hist.csv',index_col=0,parse_dates=True)
# Save three plots to in-memory files:
sav1 = io.BytesIO()
sav2 = io.BytesIO()
sav3 = io.BytesIO()
mpf.plot(df,volume=True,style='checkers',savefig=sav1)
mpf.plot(df,volume=True,style='default',savefig=sav2)
mpf.plot(df,volume=True,style='yahoo',savefig=sav3)
# Rewind the files:
_ = sav1.seek(0)
_ = sav2.seek(0)
_ = sav3.seek(0)
# Read the files as images:
img1 = m_img.imread(sav1)
img2 = m_img.imread(sav2)
img3 = m_img.imread(sav3)
# Create three side-by-side Axes:
fig = plt.figure(figsize=(21,7))
ax1 = fig.add_subplot(131)
ax2 = fig.add_subplot(132)
ax3 = fig.add_subplot(133)
# Turn the axis lines and labels off since the images will already contain them
ax1.set_axis_off()
ax2.set_axis_off()
ax3.set_axis_off()
# Plot each image on a separate axes:
ax1.imshow(img1)
ax2.imshow(img2)
ax3.imshow(img3)
plt.show() HTH. All the best. --Daniel |
Hi @DanielGoldfarb Thanks again. |
@debjyotiarr @DanielGoldfarb much needed feature 👍 |
Hello,
I'm quite new to mplfinance, but I am enjoying using it. I can plot the stock data, macd data, rsi and volume for one stock in a plot. However, I would like it if I could plot 4 or 5 similar plots side-by-side, so that they can be glanced at one go.
I am attaching two plots I made of two Indian stocks. It would be nice if I could arrange these sideways in one large plot.
Thanks in advance.
The text was updated successfully, but these errors were encountered: