Set points outside plot to lower and upper limit

by astroluv   Last Updated September 26, 2018 23:26 PM

Maybe this question exists already, but I could not find it.

I am making plots in Python. I don't want to set my axes range such that all points are included - there are some really high or really low values, and all I care about in those points is that they exist - that is, they need to be in the plot, but not on their actual value - rather, somewhere on the top of the canvas.

So i found something that helps a bit in achieving what i want to do in this question Link

So basically this thing works:

xmax=0.18
plt.(np.minimum(x,xmax),y)

But when I tried something like this then it didn't work.

xmin=0.8 
xmax=0.18
plt.(np.minimum(x, xmin,xmax),y)

How can i solve this?



Answers 1


To force the points above a threshold to a maximum level you may use np.minimum(x,xmax).
To force the points below a threshold to a minimum level you may use np.maximum(x,xmin).

To do both you may combine the two commands

xlimited = np.minimum(np.maximum(x,xmin),xmax)

Note that to have the points restricted in the vertical direction you would do this to the y values of course.

ImportanceOfBeingErnest
ImportanceOfBeingErnest
September 26, 2018 23:25 PM

Related Questions



wrong order in (matplotlib.pyplot) scatter plot axis

Updated November 15, 2017 17:26 PM


pyplot - cannot draw dotted line

Updated April 28, 2015 00:11 AM