Issue
I'm plotting an a line plot and an image side by side. Here is my code and the current output:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#creating some random data
np.random.seed(1234)
df = pd.DataFrame(
{'px_last': 100 + np.random.randn(1000).cumsum()},
index=pd.date_range('2010-01-01', periods=1000, freq='B'),
)
fig, ax = plt.subplots(1,2)
ax[0].plot(df.index, df['px_last'])
#reading the image
url = 'https://raw.githubusercontent.com/kornelski/pngquant/master/test/img/test.png'
im = plt.imread(url)
implot = ax[1].imshow(im)
The image is scaled down and the lineplot is enlarged on the y-axis. I want both figures to have the same size vertically (y-axis) - I want to have the vertical height of the line plot reduced to have the same size of the image.
I tried changing the figure size of the subplots and editing the gridspec parameter as mentioned here but that only changes the width of the image, not the height. Any help is appreciated!
Solution
One simple solution is to use automatic aspect on the image.
implot = ax[1].imshow(im, aspect="auto")
This will make the shape of your image same as your other plot.
Answered By - DumbCoder
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.