-
Notifications
You must be signed in to change notification settings - Fork 102
Description
Description
I would like to make boxplot with custom colors as in this example from matplotlib: https://matplotlib.org/3.1.1/gallery/statistics/boxplot_color.html, however, it looks like we don't have access to .set_facecolor
from a bplot['boxes']
with proplot and/or the argument fillcolor
doesn't take list.
Steps to reproduce
Expected behavior:
Here is the matplotlib example (from the link above, a bit modified):
import matplotlib.pyplot as plt
import numpy as np
# Random test data
np.random.seed(19680801)
all_data = [np.random.normal(0, std, size=100) for std in range(1, 4)]
labels = ['x1', 'x2', 'x3']
fig, ax = plt.subplots()
# rectangular box plot
bplot = ax.boxplot(all_data, patch_artist=True, labels=labels)
ax.set_title('Rectangular box plot')
# fill with colors
colors = ['pink', 'lightblue', 'lightgreen']
for patch, color in zip(bplot['boxes'], colors):
patch.set_facecolor(color)
# adding horizontal grid lines
ax.yaxis.grid(True)
ax.set_xlabel('Three separate samples')
ax.set_ylabel('Observed values')
plt.show()
Actual behavior:
Same with Proplot, I've just transformed the data in pandas DataFrame (I guess it's needed for Proplot?):
import proplot as plot
import numpy as np
import pandas as pd
# Random test data
np.random.seed(19680801)
all_data = [np.random.normal(0, std, size=100) for std in range(1, 4)]
labels = ['x1', 'x2', 'x3']
# Convert to pandas dataframe
df = pd.DataFrame(None, columns=pd.Index(labels, name='xlabel'))
for i, data in enumerate(all_data):
df[labels[i]] = data
fig, ax = plot.subplots()
# rectangular box plot
bplot = ax.boxplot(df)
# bplot = ax.boxplot(df, fillcolor=['pink', 'lightblue', 'lightgreen'])
ax.set_title('Rectangular box plot')
#####################################################
# fill with colors
colors = ['pink', 'lightblue', 'lightgreen']
for patch, color in zip(bplot['boxes'], colors):
patch.set_facecolor(color)
#####################################################
# adding horizontal grid lines
ax.format(grid=True, xlabel='Three separate samples', ylabel='Observed values')
Returns:
AttributeError: 'Line2D' object has no attribute 'set_facecolor'
So I don't know if there is another way, I tried to pass a list to the fill fillcolor
option from Proplot (as in this example: https://proplot.readthedocs.io/en/latest/1dplots.html#Box-plots-and-violin-plots), however it didn't work too.
Thanks before for the help if I missed something.
Proplot version
0.6.4