How do you limit the height of the y-axis in matplotlib figure? I am trying to both display the x axis, and reduce the height of the figure for this 1D plot.
I have tried setting ticks, figure sizes, tight_layout, margin, etc. with no luck.
Also, changing the ylimits just spans the full figure height no matter what limits I choose.
import numpy as np
import matplotlib.pyplot as plot
from matplotlib import rcParams
x = np.array([3500])
y = np.array([0])
rcParams['toolbar'] = 'None'
plot.figure(num=None, figsize=(4, 1), dpi=80, facecolor='w')
plot.axes(frameon=False)
plot.yticks([0])
plot.xlim(0, 6000)
plot.ylim(-0.1, 0.1)
plot.plot(x, y, 'x', markersize=10)
plot.show()
Current figure:

Desired figure:

Try this:
plot.ylim(lower_limit, upper_limit)
Where lower_limit is the value you want to set for the bottom of the y-axis and upper_limit is the value for the top.
np.random.seed(0)
x = np.random.randn(100)
y = np.random.randn(100)
plot.figure(num=None, figsize=(4, 1), dpi=80, facecolor='w')
plot.axes(frameon=False)
plot.ylim(-10, 10)
plot.plot(x, y, '.')

The code in the question already produces the desired result, when adding 
plot.tight_layout() at the end.

Of course decreasing figure size even further, shrinks the plot even more. E.g.
figsize=(4, 0.7)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With