S-low
S-low

Reputation: 101

Plotting inequalities in Python

I want to shade the area of the XY plane where Y<18 x^2.

This is my code:

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-.25, .25, 25)
y = np.linspace(0, 1, 20)
X,Y = np.meshgrid(x, y)
Z = masqarr(1,X, Y)

plt.imshow( (Y< 18*X**2).astype(float) , 
                extent=(X.min(),X.max(),Y.min(),Y.max()),origin="lower", cmap="Greys", alpha = 0.3, aspect='auto', interpolation = 'hanning');

However, the output I get produces a plot with plateau as in: image

How can I gat a proper smooth plot?

Upvotes: 0

Views: 79

Answers (1)

Fra93
Fra93

Reputation: 2082

This is a resolution problem, you are defining your axes with too few poitns. I tried this:

import numpy as np
import matplotlib.pyplot as plt

resolution = 200

x = np.linspace(-.25, .25, resolution)
y = np.linspace(0, 1, resolution)
X,Y = np.meshgrid(x, y)

plt.imshow( (Y< 18*X**2).astype(float) , 
                extent=(X.min(),X.max(),Y.min(),Y.max()),origin="lower", cmap="Greys", alpha = 0.3, aspect='auto', interpolation = 'hanning');

plt.show()

resolution = 25

enter image description here

resolution = 100

enter image description here

resolution = 200

enter image description here

Upvotes: 1

Related Questions