Pergunta

I have some data I want to box plot. Outliers (e.g. 20, 30) are too far away from most values (e.g. 0.0002, 0.0003) and as a consequence I can only see outliers when I plot with matplotlib.

Is there anyway to zoom in the values around the median and then let the rest of the y-axis not be in scale and display outliers too?

EDIT Here's my code in python. I would like to use inset axes, as suggested below, for each box plot I have. How can I do this in an easy way? There seems to be way too many parameters to take care of from the examples in the documentation.

plt.figure()
        ax = plt.subplot(111)
        plt.boxplot(dataToPlot)
        axins = zoomed_inset_axes(ax, 6, loc=1) # zoom = 6
# what follows is taken from example linked in the answer below. 
# I didn't get if the first argument is indeed the data this zoomed image refers to or not. 
        axins.imshow(dataToPlot[1], interpolation="nearest", origin="lower")
# here I only need the y-axis to be in [0,0.1], x-axis is no of use with vertical boxplots
        x1, x2, y1, y2 = -1.5, -0.9, 0.0, 0.1
        axins.set_xlim(x1, x2)
        axins.set_ylim(y1, y2)
        plt.xticks(visible=True)
        plt.yticks(visible=True)
        plt.savefig( 'somewhere.jpeg', bbox_inches=0)
Foi útil?

Solução

You could do an inset axes as described on this page, about 1/2 way down.

inset axes

Outras dicas

Very old question, but I came across this looking for something similar. I solved this by adding sym='' (this option may have not existed 7 years ago!) which tells boxplot not to show fliers (anything past the whiskers).

So for anyone else who comes across this, you might try changing line 3 in the question to:

plt.boxplot(dataToPlot, sym='')
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top