gpt4 book ai didi

python - 在 Plotly 3.0 中设置图例文本颜色

转载 作者:行者123 更新时间:2023-11-30 22:12:07 24 4
gpt4 key购买 nike

我刚刚安装了最新的 Plotly (3.0),但无法设置图例文本颜色。

这是我的代码:

import plotly.graph_objs as go
import numpy as np

x = np.random.randn(1000)
y = np.random.randn(1000)

fig = go.FigureWidget({'x':x,'y':y,'type':'histogram2dcontour','colorscale':'Viridis'}],
layout=go.Layout(title='test',width=700,plot_bgcolor='rgba(0,0,0,0)',
paper_bgcolor='rgba(0,0,0,0)'))

fig.layout.titlefont.color = 'orange'
fig.layout.xaxis.color = 'white'
fig.layout.yaxis.color = 'white'
fig.layout.legend.font.size = 2000
fig.layout.legend.font.color = 'red'

fig

如下所示,下面的图例文本保持不变。奇怪的是fig.layout.legend.font.color的属性包括capitalise、isdigit类方法等。

这是一个错误还是我遗漏了什么?

非常感谢任何帮助。

谢谢。

Legend text unchanged.

最佳答案

因为您使用的是 histogram2contour,右侧的颜色条不是图例,而是实际上一个名为 colorbar 的对象。要更新它,您可以在跟踪中配置它的属性。下面有一个示例,我将刻度线设置为橙色,将标题设置为红色。我使用 Jupyter Notebooks 创建示例,因此我必须将其配置为离线,但您也没有。 Here是颜色条对象的文档。

 import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)

import numpy as np

x = np.random.uniform(-1, 1, size=500)
y = np.random.uniform(-1, 1, size=500)

trace = [go.Histogram2dContour(
x = x,
y = y,
colorbar=dict(
title='Colorbar',
tickfont={'color':'#E90' },
titlefont={"color":'#FF0000'}
),
)]

iplot(trace, filename = "Basic Histogram2dContour")

enter image description here

关于python - 在 Plotly 3.0 中设置图例文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51210306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com