0
這是我想要做的,數據框的所有列的直方圖,但沒有網格軸。下面的代碼工作,但最好我想一個更好的解決方案(如將參數傳遞給HIST)如何讓網格軸對熊貓數據框hist()不可見?
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
X = np.asarray([50]*25+[30]*10)
X2 = np.asarray([90]*10+[20]*25)
X3 = np.asarray([10]*15+[70]*20)
df = pd.DataFrame(np.vstack([X, X2, X3]).T)
def plot_hists(df, nbins=10, figsize=(8, 8), disable_axis_labels = True):
plt.close('all')
grid_of_ax_hists = df.hist(bins=nbins, figsize=figsize)
if disable_axis_labels:
for row in grid_of_ax_hists:
for ax in row:
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
plt.show()
df.hist()
plt.subplots()
plot_hists(df, nbins=10, figsize=(8, 8), disable_axis_labels = True)
遺憾的是不工作,我得到「UserWarning:可以輸出多種次要情節,包含傳遞的軸的身影正在清理 ‘被清除’,UserWarning」 ,然後是輸出還是有情節軸 –