plt.boxplot() returns a dictionary where the fliers key contains the top and bottom flyers as line2d objects. You can manipulate them before doing the following:
Only on matplotlib> = 1.4.0
bp = plt.boxplot(data, whis=[5, 95], showfliers=True) # Get a list of Line2D objects, representing a single line from the # minimum to the maximum flier points. fliers = bp['fliers'] # Iterate over it! for fly in fliers: fdata = fly.get_data() fly.set_data([fdata[0][0],fdata[0][-1]],[fdata[1][0],fdata[1][-1]])
In older versions
If you are using an older version of matplotlib, the flyers for each box are represented by two lines, not one. Thus, the loop will look something like this:
import numpy as np for i in range(len(fliers)): fdata = fliers[i].get_data() # Get the index of the maximum y in data if # i is 0 or even, else get index of minimum y. if i%2 == 0: id = np.where(fdata[1] == fdata[1].max())[0][0] else: id = np.where(fdata[1] == fdata[1].min())[0][0] fliers[i].set_data([fdata[0][id], fdata[1][id]])
Also note that the showfliers argument showfliers not exist in matplotlib <1.4x, and the whisk argument whisk not accept lists.
Of course (for simple applications) you can draw a box without pilots and add maximum and minimum points to the graph:
bp = plt.boxplot(data, whis=[5, 95], showfliers=False) sc = plt.scatter([1, 1], [data.min(), data.max()])
where [1, 1] is the x-position of the points.
Geotob
source share