【发布时间】:2021-12-17 00:16:42
【问题描述】:
我可以使用 2D Histograms or Density Heatmaps 绘制我的 DataFrame 的一列。
flights = pd.read_csv('Flights dataset.csv')
fig = px.density_heatmap(flights_dest, x='DEST_CITY_NAME', marginal_x="histogram")
fig.show()
我想在包含两个水平子图的图中使用密度热图从两个不同的 DataFrame 中绘制两列。
从Subplots in Python看到应该使用plotly.graph_objects库来实现子图:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(rows=2, cols=1)
fig.add_trace(
go.Scatter(x=[1, 2, 3], y=[4, 5, 6]),
row=1, col=1
)
fig.add_trace(
go.Scatter(x=[20, 30, 40], y=[50, 60, 70]),
row=1, col=2
)
fig.update_layout(height=600, width=800, title_text="Side By Side Subplots")
fig.show()
但我在 plotly.graph_objects 库中找不到使用 plotly.express 创建的 Density Heatmaps 的等价物。
知道如何实现它吗?
【问题讨论】:
-
我不明白二维直方图和密度热图是否相同,但我可以通过在子图中指定 go.Histgram2d() 来绘制具有不同数据的图形。彩条需要控制。
-
@r-beginners in
density_heatmap我可以添加marginal_x="histogram"。但是,在Histgram2d()中,它不支持。 -
直方图和热图有多重要?我可以为热图找到解决方案
-
@RobRaymond 这不是必须的,但我更喜欢拥有它
标签: python dataframe plotly heatmap plotly-python