[英]plotly express heatmap cell size
如何更改 plotly express 熱圖中的單元格大小? 我需要更大的細胞
import plotly.express as px
fig1 = px.imshow(df[col],color_continuous_scale='Greens')
fig1.layout.yaxis.type = 'category'
fig1.layout.xaxis.type = 'category'
fig1.layout.yaxis.tickmode = 'linear'
fig1.layout.xaxis.tickmode = 'linear'
fig1.layout.xaxis.tickangle = 65
fig1.layout.autosize = True
fig1.layout.height = 500
fig1.layout.width = 500
fig1.show()
結果(非常窄)
由於顏色條,'px' 可能無法使它成為正方形,那么為什么不使用 'go' 呢?
import plotly.graph_objects as go
fig = go.Figure(data=go.Heatmap(
z=[[1, 20, 30],
[20, 1, 60],
[30, 60, 1]]))
fig.show()
設置圖形大小。
fig.layout.height = 500
fig.layout.width = 500
px 上的示例
import plotly.express as px
data=[[1, 25, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, 5, 20]]
fig = px.imshow(data,
labels=dict(x="Day of Week", y="Time of Day", color="Productivity"),
x=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
y=['Morning', 'Afternoon', 'Evening']
)
fig.update_xaxes(side="top")
fig.layout.height = 500
fig.layout.width = 500
fig.show()
有點晚了,但如果你想讓單元格更寬,使用這個:
fig1 = px.imshow(df[col],color_continuous_scale='Greens', aspect='auto')
將 aspect 參數設置為“auto”將使用非方形圖塊填充繪圖區域。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.