boxplot python code example
Example 1: python boxplot show mean
import matplotlib.pyplot as plt
import numpy as np
data_to_plot = np.random.rand(100,5)
fig = plt.figure(1, figsize=(9, 6))
ax = fig.add_subplot(111)
bp = ax.boxplot(data_to_plot, showmeans=True)
plt.show()
Example 2: python matplotlib boxplot
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(19680801)
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))
fig1, ax1 = plt.subplots()
ax1.set_title('Basic Plot')
ax1.boxplot(data)
Example 3: boxplot python
import numpy as np
import matplotlib.pyplot
matrix=np.random.rand(10,10)
plt.boxplot(matrix)
Example 4: sns.boxplot code
sns.boxplot("var")
Example 5: boxplot code
sns.boxplot("var")
Example 6: python how to make boxplots with pandas and seaborn
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
data_url = 'http://bit.ly/2cLzoxH'
gapminder = pd.read_csv(data_url)
print(gapminder.head(3))
gapminder_2007 = gapminder[gapminder['year']==2007]
gapminder_2007.head(3)
bplot = sns.boxplot(y='lifeExp', x='continent',
data=gapminder_2007,
width=0.5,
palette="colorblind")
bplot = sns.boxplot(y='lifeExp', x='continent',
data=gapminder_2007,
width=0.5,
palette="colorblind")
bplot = sns.stripplot(y='lifeExp', x='continent',
data=gapminder_2007,
jitter=True,
marker='o',
alpha=0.5,
color='black')
bplot = sns.boxplot(y='lifeExp', x='continent',
data=gapminder_2007,
width=0.5,
palette="colorblind")
bplot = sns.swarmplot(y='lifeExp', x='continent',
data=gapminder_2007,
color='black',
alpha=0.75)