I'm struggling with this strange behavior in the matplotlib pyplot library.
The actual plot is more complex but I've reduced it to these few lines of python code:
from matplotlib import pyplot as plt
import numpy as np
def plot(w, h):
num_samples = int(w * h)
x = w * np.random.rand(num_samples)
y = h * np.random.rand(num_samples)
plt.figure(figsize=(w, h))
plt.xticks(range(w))
plt.xlim(0, w)
plt.ylim(0, h)
plt.scatter(x, y)
plt.grid()
It basically creates a scatter plot given width and height parameters.
If I invoke this function like plot(5, 3), it will produce this figure:

I can use the function with greater width values, generating long plots like plot(100, 3):

But if I use it with a greater width it creates a "broken plot" plot(450, 3):

Note that
- the lines of the containing frame are kind of dashed?
- there are scatter dots outside the containing frame.

why? Is it a bug in the library?
plt.figure(figsize=(450, 3))would be much too large, especially when running in interactive mode. See e.g. Setting figure size to be larger than screen size in matplotlib. In this post, one of matplotlib maintainers mentions a maximum figsize of 50 inches.