Pandas Boxplots中的数字名称

时间:2017-06-28 16:56:10

标签: pandas matplotlib

我使用pandas创建了2个箱图。 然后每个数字都以(defmulti do-something resolve-it) (defmethod do-something :do-it [] (println "do-it")) (defmethod do-something :oh-no [] (println "oh-no"))

引用

当试图显示图时,只显示最后一个箱图。就像fig1被覆盖了一样。 显示两个箱图的正确方法是什么?

这是示例代码

plt.gcf()

2 个答案:

答案 0 :(得分:1)

创建一个有两个轴的图形并分别绘制每个轴

fig, axes = plt.subplots(2)

dates   = pd.date_range('20000101', periods=10)
df      = pd.DataFrame(index=dates)
df['A'] = np.cumsum(np.random.randn(10))  
df['B'] = np.random.randint(-1,2,size=10)
df['C'] = range(1,11)
df['D'] = range(12,22)

# first figure
df[['A','B']].boxplot(ax=axes[0])  # Added `ax` parameter

# second figure
df[['C','D']].boxplot(ax=axes[1])  # Added `ax` parameter

plt.show()

enter image description here

答案 1 :(得分:1)

为了得到两个数字,在绘制之前定义数字。您可以使用数字列举数字。

plt.figure(1)
# do something with the first figure

plt.figure(2)
# do something with the second figure

完整示例:

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

dates   = pd.date_range('20000101', periods=10)
df      = pd.DataFrame(index=dates)
df['A'] = np.cumsum(np.random.randn(10))  
df['B'] = np.random.randint(-1,2,size=10)
df['C'] = range(1,11)
df['D'] = range(12,22)

# first figure
fig1=plt.figure(1)
ax_boxplt1 = df[['A','B']].boxplot()

# second figure
fig2=plt.figure(2)
ax_boxplt2  = df[['C','D']].boxplot()

plt.show()

enter image description here

相关问题