spo*_*234 1 python matplotlib pandas
根据文档,我在 pandas 中制作了这个图:
import pandas as pd
import numpy as np
import pyplot as plt
df = pd.DataFrame(np.random.rand(140, 4), columns=['A', 'B', 'C', 'D'])
df['models'] = pd.Series(np.repeat(['model1','model2', 'model3', 'model4', 'model5', 'model6', 'model7'], 20))
plt.figure()
bp = df.boxplot(by="models")
Run Code Online (Sandbox Code Playgroud)
我怎样才能修改这个情节?
我想:
以及如何将此图另存为 pdf ?
layoutset_xlabel('')figure.subtitle()figsize=(w,h)(英寸)注意:该行将np.asarray(bp).reshape(-1)子图的布局(例如 2x2)转换为数组。
代码 :
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.DataFrame(np.random.rand(140, 4), columns=['A', 'B', 'C', 'D'])
df['models'] = pd.Series(np.repeat(['model1','model2', 'model3', 'model4', 'model5', 'model6', 'model7'], 20))
bp = df.boxplot(by="models",layout=(4,1),figsize=(6,8))
[ax_tmp.set_xlabel('') for ax_tmp in np.asarray(bp).reshape(-1)]
fig = np.asarray(bp).reshape(-1)[0].get_figure()
fig.suptitle('New title here')
plt.show()
Run Code Online (Sandbox Code Playgroud)
结果: