Issue
It seems the only way I can make the figure a rectangle (to save vertical space), is by skewing the image which makes all text on the screen skew also.
How can I make the height of the figure smaller, without touching the width, or the text presentation?
Solution
The figsize
keyword argument can be passed when creating a matplotlib figure using plt.figure()
as shown below.
The figsize
keyword argument states the figure size in inches. You pass a 2-item tuple of the form (width, height)
. This allows you to choose the size (and hence aspect ratio) of your figure before you plot any data. Below I have created a figure with width=16in
and height=4in
.
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 1000)
y = np.sin(x)
fig = plt.figure(figsize=(16,4))
ax = fig.add_subplot(1,1,1)
ax.plot(x,y)
ax.set_xlabel('x')
ax.set_ylabel('y')
plt.show()
Answered By - Ffisegydd
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.