Note that there are some explanatory texts on larger screens.

plurals
  1. POPython - matplotlib axes limits approximate ticker location
    primarykey
    data
    text
    <p>When no axes limits are specified, matplotlib chooses default values as nice, round numbers below and above the minimum and maximum values in the list to be plotted. </p> <p>Sometimes I have outliers in my data and I don't want them included when the axes are selected. I can detect the outliers, but I don't want to actually delete them, just have them be beyond the area of the plot. I have tried setting the axes to be the minimum and maximum value in the list not including the outliers, but that means that those values lie exactly on the axes, and the bounds of the plot do not line up with ticker points.</p> <p>Is there a way to specify that the axes limits should be in a certain range, but let matplotlib choose an appropriate point? </p> <p>For example, the following code produces a nice plot with the y-axis limits automatically set to (0.140,0.165):</p> <pre><code>from matplotlib import pyplot as plt plt.plot([0.144490353418, 0.142921640661, 0.144511781706, 0.143587888773, 0.146009766101, 0.147241517391, 0.147224266382, 0.151530932135, 0.158778411784, 0.160337332636]) plt.show() </code></pre> <p><img src="https://i.stack.imgur.com/Ufyyh.png" alt="Plot from the first code example."></p> <p>After introducing an outlier in the data and setting the limits manually, the y-axis limits are set to slightly below 0.145 and slightly above 0.160 - not nearly as neat and tidy. </p> <pre><code>from matplotlib import pyplot as plt plt.plot([0.144490353418, 0.142921640661, 0.144511781706, 0.143587888773, 500000, 0.146009766101, 0.147241517391, 0.147224266382, 0.151530932135, 0.158778411784, 0.160337332636]) plt.ylim(0.142921640661, 0.160337332636) plt.show() </code></pre> <p><img src="https://i.stack.imgur.com/kXT4D.png" alt="Plot from the second code example."></p> <p>Is there any way to tell matplotlib to either ignore the outlier value when setting the limits, or set the axes to 'below 0.142921640661' and 'above 0.160337332636', but let it decide an appropriate location? I can't simply round the numbers up and down, as all my datasets occur on a different scale of magnitude.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload