0

I have a problem with plotting in matplotlib, but the question may be more about handling numpy arrays than about the plotting itself - a solution in matplotlib would perhaps be more desirable!

The problem is this: I have two ndarrays, xvals and yvals of shape (1000,), to be interpreted as fitted x and y coordinates (they are supposed to be centered around some value). Some elements (but not very few!) have extremely large absolute values compared to the others (by a factor 1000 or larger). The reason I can't set the axes to some fixed value is that mean(xvals) and mean(yvals) and their standard deviation varies between the plots quite a bit.

I want to do a 2d plot of the points with something like plt.plot(xvals, yvals, '.'), and it is important for me to set the axes automatically so that one can see the main distribution of points clearly. The reason that is has to be done automatically is that I'm doing ~100 plots and must be able to name and change things in the plots repeatedly.

I have already tried to use plt.axis([mean(xvals) - k * std(xvals), mean(xvals) + k * std(xvals), mean(yvals) - k * std(yvals), mean(yvals) + k * std(yvals)]), trying out different values of k, but none seems to work for all my plots.

Here are two pictures, showing (1) what I get (without using axis() at all, and (2) what I roughly would like to have outputted:

Wrong... About right...

I hope I have provided enough information, please tell me otherwise and I will try to provide it!

4

1 回答 1

0

也许你可以使用这样的东西:

x = sorted(xvals)
y = sorted(yvals)
plt.axis([x[.1*len(x)], x[.9*len(x)], y[.1*len(y)], y[.9*len(y)]])

它忽略了两边 10% 的点。

于 2013-04-19T16:10:23.570 回答