1

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?

astroluv
  • 798
  • 1
  • 8
  • 25
  • In the link answers use try this (to do it on the x axis instead of y): `ax.scatter(np.minimum(x, ymax),y) ` – Lucas Sep 26 '18 at 23:23
  • yeah but that's only for the upper limit of x axis but if i want to add the lower limit as well? Then how do i do it? – astroluv Sep 26 '18 at 23:25

1 Answers1

2

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
  • 321,279
  • 53
  • 665
  • 712