Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

matplotlib boxplot colors

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, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(9, 4))

# rectangular box plot
bplot1 = ax1.boxplot(all_data,
                     vert=True,  # vertical box alignment
                     patch_artist=True,  # fill with color
                     labels=labels)  # will be used to label x-ticks
ax1.set_title('Rectangular box plot')

# notch shape box plot
bplot2 = ax2.boxplot(all_data,
                     notch=True,  # notch shape
                     vert=True,  # vertical box alignment
                     patch_artist=True,  # fill with color
                     labels=labels)  # will be used to label x-ticks
ax2.set_title('Notched box plot')

# fill with colors
colors = ['pink', 'lightblue', 'lightgreen']
for bplot in (bplot1, bplot2):
    for patch, color in zip(bplot['boxes'], colors):
        patch.set_facecolor(color)

# adding horizontal grid lines
for ax in [ax1, ax2]:
    ax.yaxis.grid(True)
    ax.set_xlabel('Three separate samples')
    ax.set_ylabel('Observed values')

plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: installation of uvicorn with only pure python dependencies 
Python :: python create file if doesnt exist 
Python :: first column of a dataframe python 
Python :: System.Windows.Forms.DataGridView.CurrentRow.get returned null. c# 
Python :: label encoding in python 
Python :: seaborn boxplot 
Python :: django migrate not creating tables 
Python :: clone website 
Python :: how to open pickle file 
Python :: python lambda function map 
Python :: python get file name 
Python :: create a blank image 
Python :: pyside 
Python :: counter python 
Python :: max of three numbers in python 
Python :: python return specific elements from list 
Python :: pandas index to datetime 
Python :: change value in excel using python 
Python :: how to check if a list is nested or not 
Python :: name of columns pandas 
Python :: how to find a word in list python 
Python :: python copy 
Python :: python for loop one line 
Python :: calculate percentile pandas dataframe 
Python :: maxsize in python 
Python :: convert ndarray to csr_matrix 
Python :: change default port django 
Python :: python default dic 
Python :: python list remove at index 
Python :: Python t date from a timestamp 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =