generating pandas bar and placed side by side boxplots

1, Code

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# 生成数据,创建 DataFrame
np.random.seed(27)
data = np.random.rand(7, 3)
index = ['Customer ' + str(i) for i in range(1, 8)]
Metrics = ['Metric ' + str(i) for i in range(1, 4)]
df = pd.DataFrame(data, index=index, columns=pd.Index(Metrics, name='Metrics'))

# Set the graphics and layout properties 
plt.style.use ( ' ggplot ' ) 
Fig = plt.figure ( ' Barry Hammonds ' ) 
axes = fig.subplots (= nrows. 1, ncols = 2 ) 
AX1, AX2 of = axes.ravel () 

# Create a coordinate system in the first vertical bar 
df.plot (kind = ' bar ' , AX = AX1, Alpha = 0.7, title = ' bar Plot ' ) 
plt.setp (ax1.get_xticklabels (), rotation = 45, 10 = fontSize ) 
plt.setp (ax1.get_yticklabels (), rotation = 0, fontSize = 10 ) 
ax1.set_xlabel ( ' the Customer '), Ax1.set_ylabel ( ' the Value ' ) 

# Create box plots in the second coordinate system 
Colors = dict (= Boxes ' DarkBlue ' , Whiskers = ' Gray ' , medians = ' R & lt ' , Caps = ' K ' ) 
DF .plot (kind = ' Box ' , = AX2 of AX, Color = Colors, sym = ' R & lt. ' , title = ' Box Plot ' ) 
plt.setp (ax2.get_xticklabels (), rotation = 45, fontSize =. 11 ) 
PLT .setp (ax2.get_yticklabels (), rotation = 0,fontsize=11) 
Ax2.set_xlabel ( ' the Metric ' ), ax2.set_ylabel ( ' the Value ' ) 

# adjusting pattern display position 
fig.subplots_adjust (left = 0.05, 0.2 = bottom, right = 0.95 , 
                    Top = 0.95, hspace = 0.1, 0.1 = wspace ) 

plt.show ()

2 graphics follows

 

 

。。。

Guess you like

Origin www.cnblogs.com/shanger/p/12046415.html
Recommended