Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flier colors in boxplot with matplotlib

According to the documentation, the Axes.boxplot function takes a dictionary flierprop as argument to define the properties of the outliers. Unfortunately, I can't find the documentation concerning this dictionary. In particular, I would like to define the color of the border of the marker.

By default, empty circles are drawn. One can set the face color, as shown in the example. Nevertheless, the circle border is always a black line. I tried with the keys color and markercolor (the former has no effect, the latter produces an error).

What should I do to set a color for the marker line?

like image 331
Spiros Avatar asked Apr 11 '17 09:04

Spiros


People also ask

How do you color a boxplot?

To change the color of box of boxplot in base R, we can use col argument inside boxplot function.

What are fliers in boxplot?

fliers : points representing data that extend beyond the whiskers (fliers). means : points or lines representing the means.

How to change the color of a box plot in Matplotlib?

You can change the color of a box plot using setp on the returned value from boxplot (). This example defines a box_plot () function that allows the edge and fill colors to be specified: import matplotlib.pyplot as plt def box_plot (data, edge_color, fill_color): bp = ax.boxplot (data, patch_artist=True) for element in ['boxes', 'whiskers', ...

Can you add patterns to matplotlib plots?

For now, unfortunately, matplotlib has rather limited functionality for this purpose. Moreover, there is no unique approach for different types of plots. In this article, we’re going to explore how to add patterns to bar plots, histograms, box plots, and pie charts.

What is a box plot in Python?

Box Plot in Python using Matplotlib Last Updated : 30 Apr, 2020 A Box Plot is also known as Whisker plot is created to display the summary of the set of data values having properties like minimum, first quartile, median, third quartile and maximum.

What are the keys of a boxplot?

That dictionary has the following keys (assuming vertical boxplots): boxes: the main body of the boxplot showing the quartiles and the median’s confidence intervals if enabled. medians: horizontal lines at the median of each box. whiskers: the vertical lines extending to the most end, non-outlier data points.


1 Answers

To set marker color use property markerfacecolor but for border color - markeredgecolor:

import matplotlib.pyplot as plt
import numpy as np

# fake up some data
spread = np.random.rand(50) * 100
center = np.ones(25) * 50
flier_high = np.random.rand(10) * 100 + 100
flier_low = np.random.rand(10) * -100
data = np.concatenate((spread, center, flier_high, flier_low), 0)

# plot. Set color of marker edge
flierprops = dict(marker='o', markerfacecolor='r', markersize=12,
                  linestyle='none', markeredgecolor='g')
plt.boxplot(data, flierprops=flierprops)

plt.show()

enter image description here

According to @Spiros the flierprops dictionary is documented here like other boxplot properties: http://matplotlib.org/users/dflt_style_changes.html?highlight=flierprops#boxplot

like image 132
Serenity Avatar answered Oct 07 '22 06:10

Serenity