python - Plotly:如何保持固定的图表高度大小但可变的表格行数
问题描述
我有一个 Plotly Python 堆叠条形图,其中有一个数据表,下面有几个数据行,这是我创建高度为 430(高度 = 430)的图表布局的代码:
layout = dict(title='Fruit & Veg',
width=1200,
height=430,
barmode='stack',
xaxis=dict(domain=[0, 0.75]),
yaxis=dict(domain=[0.65, 1]),
showlegend=True,
legend=dict(y=0.98, x=0.78, traceorder='normal', bgcolor='#E2E2E2', borderwidth=0),
margin=go.layout.Margin(l=30, r=30, b=30, t=50, pad=0),
template='none'
)
这是它用 9 个表格行生成的图像:
太棒了。现在我想创建更多具有相同条形图高度区域的图表,但在其下方的表格中具有更多行。但是,当我将高度值从 430 增加到 800(高度=800)时,如下面的代码所示:
layout = dict(title='Fruit & Veg',
width=1200,
height=800,
barmode='stack',
xaxis=dict(domain=[0, 0.75]),
yaxis=dict(domain=[0.65, 1]),
showlegend=True,
legend=dict(y=0.98, x=0.78, traceorder='normal', bgcolor='#E2E2E2', borderwidth=0),
margin=go.layout.Margin(l=30, r=30, b=30, t=50, pad=0),
template='none'
)
我确实在下面有更多的表格行(20 行而不是 9 行),但条形图高度也变得更高/拉伸,它似乎是图表总高度的百分比,参见图片:
问题出在 yaxis dict 属性中,但我不知道如何设置固定的条形图高度,而不管整体图表+表格图像大小的高度如何。
关于如何正确设置这个 yaxis 值的任何想法?
解决方案
好的,我能够回答我自己的问题,问题是我还在 go.Table 定义中指定了一个固定的高度,但我忘记了:
go.Table(
domain=dict(x=[0, 1],
y=[0, 0.6]),
type='table',
...,
...
)
我重写了我的代码以动态更改 go.Table 中的 y 值和 go.Layout 中的 yaxis 值,具体取决于我想要显示的行数。
推荐阅读
- wordpress - 使用 wordpress 设置 API 将数据数组保存到数据库
- android - 如何在此代码中显示另一个文本视图?
- vba - 删除记录时出现错误 1004“应用程序定义或对象定义错误”
- c# - 在调试模式 xamarin 表单上启动应用程序到设备时遇到无法获取提供程序 com.google.firebase.provider.FirebaseInitProvider 错误
- c# - C#:增加 HttpWebRequest 的并发连接数
- python - 更改“创建”按钮 flask-admin 的链接位置
- javascript - 修复了 ios Safari 弹跳时标题消失的问题
- java - 在Java中按值过滤地图?
- ruby-on-rails - Friendly_id PG::InvalidTextRepresentation:错误:整数输入语法无效:
- python - 编写一个小型 Python 字典