Ricky Robinson
Ricky Robinson

Reputation: 22903

Boxplots with not-in-scale y-axis

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?

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)

Upvotes: 0

Views: 1652

Answers (1)

gph
gph

Reputation: 1360

I solved this by adding sym='' which tells boxplot not to show fliers (anything past the whiskers).

Try changing line 3 in the question to:

plt.boxplot(dataToPlot, sym='')

Upvotes: 1

Related Questions