Set points outside plot to upper limit
<p>Maybe this question exists already, but I could not find it. </p>

<p>I am making a scatter plot in Python. For illustrative purposes, I don't want to set my axes range such that all points are included - there may be 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.</p>

<p>I know that in IDL there is a nice short syntax for this: in <code>plot(x,y&lt;value)</code> any value in y greater than <code>value</code> will simply be put at <code>y=value</code>.</p>

<p>I am looking for something similar in Python. Can somebody help me out?</p>

<p>you can just use <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.minimum.html" rel="nofollow"><code>np.minimum</code></a> on the <code>y</code> data to set anything above your upper limit to that limit. <code>np.minimum</code> calculates the minima element-wise, so only those values greater than <code>ymax</code> will be set to <code>ymax</code>.</p>

<p>For example: </p>

<pre><code>import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0., np.pi*2, 30)
y = 10. * np.sin(x)

ymax = 5

fig, ax = plt.subplots(1)
ax.scatter(x, np.minimum(y, ymax))

plt.show()
</code></pre>

<p><a href="http://i.stack.imgur.com/cEMSo.png" rel="nofollow"><img src="http://i.stack.imgur.com/cEMSo.png" alt="enter image description here"></a></p>

python matplotlib plot limits