Python 绘图仪中的水平表格和图表
嗨, 我想在plotly中创建水平表和图表(类似于子图)。我无法创建它。请帮帮我Python 绘图仪中的水平表格和图表,python,plotly,bar-chart,Python,Plotly,Bar Chart,嗨, 我想在plotly中创建水平表和图表(类似于子图)。我无法创建它。请帮帮我 谢谢我想你的意思是: 使用以下代码创建: from plotly.subplots import make_subplots import plotly.express as px import plotly.graph_objs as go fig = make_subplots( rows=1, cols=2, shared_xaxes=True, horizontal_spacing
谢谢我想你的意思是: 使用以下代码创建:
from plotly.subplots import make_subplots
import plotly.express as px
import plotly.graph_objs as go
fig = make_subplots(
rows=1, cols=2,
shared_xaxes=True,
horizontal_spacing=0.03,
specs=[[{"type": "table"}, {"type": "bar"}]]
)
fig.add_trace(
go.Table(
header=dict(
values=['Country', 'Year', 'Population'],
font=dict(size=12),
align="left"
),
cells=dict(
values=[
['United States', 2000, 282200000],
['Canada', 2000, 27790000],
['United States', 2005, 295500000],
],
align = "left")
),
row=1, col=1
)
fig.add_trace(
go.Bar(
x=[1, 2, 3],
y=[4, 5, 6],
),
row=1, col=2
)
fig.update_layout(
height=500,
showlegend=False,
title_text="example plot",
)
fig.show()
我用的不是工厂
使用样本数据和布局,您可以根据需要进行更改。非常感谢。您好,这对我很有用,谢谢。唯一的问题是:我的结果集是一个数据帧(从SQL查询中提取)。是否可以从我的数据帧中获取字典值,而不是硬编码x和y轴的值?是的,您可以直接将x和y值指定为df['col1']和df['col2']。无需硬编码值。这只是个例子,明白了。非常感谢你。