繁体   English   中英

Plotly:如何设置 plotly.express 图表的 position 与 facet?

[英]Plotly: How to set position of plotly.express chart with facet?

有没有办法改变标题 position 图表绘制

fig=px.histogram(df,x='x',facet_row='Date',color='c',
             barmode='overlay',facet_col='number',height=500)
for a in fig.layout.annotations:
    a.text = a.text.split("=")[1]
fig.show()

从每个子图的右到中?

在此处输入图像描述

我不是 100% 确定你想把什么移到哪里,但听起来你希望右边的日期出现在图表中间的刻面之间。 在图的结构中,那些是注释。 你可以把它们放在你想要的任何地方,但是如何以及在哪里将取决于你的特定人物的结构。 由于您尚未提供数据集,因此我将使用plotly epress 文档中的示例向您展示一些一般原则,这些示例应该可以帮助您。 如果您提供数据集和完整的工作代码,我将能够为您提供详细信息。

Plot 1:

在此处输入图像描述

代码 1:

import plotly.express as px
df = px.data.tips()
fig = px.scatter(df, x="total_bill", y="tip", facet_row="time", facet_col="day", color="smoker", trendline="ols",
          category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})
fig.show()

在这里,与您要移动的元素相对应的元素是'time=Lunch''time=Dinner' 因此,在这种情况下,可以将元素放置在沿 x 轴的任何位置,如下所示:

代码:2

for i, a in enumerate(fig['layout']['annotations']):
  if a['text'][:4]=='time':
    a['x']=0.475
    a['font']=dict(size = 10, color='rgba(255,0,200,0.8)')
    print(a)
fig.show()

Plot:2

在此处输入图像描述

我知道这是一个有点老套的方法,但我希望你会发现它有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM