pd.DataFrame.hist 的情节等价物 [英] Plotly equivalent for pd.DataFrame.hist
本文介绍了pd.DataFrame.hist 的情节等价物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种使用 plotly 来模仿 pandas.DataFrame
的 hist
方法的方法.下面是一个使用 hist
方法的例子:
I am looking for a way to imitate the hist
method of pandas.DataFrame
using plotly. Here's an example using the hist
method:
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 做到这一点?
How would one do this using plotly?
推荐答案
您可以使用 plotly 的 make_subplots() 函数制作子图.从那里,您可以在子图中添加具有所需数据和位置的轨迹.
You can make subplots using plotly's make_subplots() function. From there you add traces with the desired data and position within the 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
)
这篇关于pd.DataFrame.hist 的情节等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文