Python pd.DataFrame.hist的绘图等效项

Python pd.DataFrame.hist的绘图等效项,python,pandas,plot,plotly,Python,Pandas,Plot,Plotly,我正在寻找一种方法来模仿使用plotly的pandas.DataFrame的hist方法。下面是一个使用hist方法的示例: import seaborn as sns import matplotlib.pyplot as plt # load example data set iris = sns.load_dataset('iris') # plot distributions of all continuous variables iris.drop('species',inplac

我正在寻找一种方法来模仿使用plotly的
pandas.DataFrame
hist
方法。下面是一个使用
hist
方法的示例:

import seaborn as sns
import matplotlib.pyplot as plt

# load example data set
iris = sns.load_dataset('iris')

# plot distributions of all continuous variables
iris.drop('species',inplace=True,axis=1)
iris.hist()
plt.tight_layout()
产生:


如何使用plotly实现这一点?

plotly内置了一个直方图函数,因此您只需编写即可

px.histogram()

并传递数据列和x=label,它应该可以工作。这里是文档的链接

您可以使用plotly的make_subplot()函数生成子图。从那里,您可以添加带有子批次中所需数据和位置的记录道

from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig = make_subplots(rows=2, cols=2)

fig.add_trace(
    go.Histogram(x=iris['petal_length']),
    row=1, col=1
)
fig.add_trace(
    go.Histogram(x=iris['petal_width']),
    row=1, col=2
)
fig.add_trace(
    go.Histogram(x=iris['sepal_length']),
    row=2, col=1
)
fig.add_trace(
    go.Histogram(x=iris['sepal_width']),
    row=2, col=2
)

我已经尝试过plotly.express.histogram(iris),但这会将直方图放在彼此的顶部。是否还有一种更自动化的方法,在不必定义行和列以及各自的索引,并且变量数量未知的情况下执行此操作?