[英]Plotly Dash - Gradient Lines
Is it possible using Plotly Dash to create line graphs in which the line colors are gradient (purely for aesthetics)?是否可以使用 Plotly Dash 创建线图,其中线 colors 是渐变的(纯粹是为了美观)?
I tried using something like我尝试使用类似的东西
'line': {'color': 'linear-gradient(90deg, red, red 60%, white)' }
example of entire graph code in plotly dassh plotly dashsh 中的整个图形代码示例
dcc.Graph(
id='MORTGAGE_RATES',
figure={
'data': [
{ "x": MORTGAGE30US['date'],"y": MORTGAGE30US['value'],"mode": "lines","name": '30 YR', 'line': {'color': 'linear-gradient(90deg, red, red 60%, white)' }},
{ "x": MORTGAGE15US['date'],"y": MORTGAGE15US['value'],"mode": "lines","name": '15 YR',},
],
'layout': {
'title': 'MORTGAGE RATES',
"paper_bgcolor": "rgb(46, 54, 65)",
"plot_bgcolor": "rgb(46, 54, 65)",
'font': {
'color': "rgb(255,255,255)"
}
}
}
)
This feature is not yet available for 2D line plots, it is currently only available for 3D line plots, see https://github.com/plotly/plotly.js/issues/581 .此功能尚不适用于 2D 线图,目前仅适用于 3D 线图,请参阅https://github.com/plotly/plotly.js/issues/581 。 It is however possible to use a colorscale in a 2D plot if you use markers instead of lines, see the example below.
但是,如果您使用标记而不是线条,则可以在 2D plot 中使用色标,请参见下面的示例。
import plotly.graph_objects as go
import numpy as np
t = np.linspace(0, 10, 1000)
x, y = t, np.cos(t)
data = go.Scatter(x=x, y=y, mode='markers', marker={'color': x, 'colorscale': 'Rainbow', 'size': 10})
layout = dict(plot_bgcolor='white', margin=dict(t=0, b=0, r=0, l=0, pad=0),
xaxis=dict(showgrid=False, zeroline=False, mirror=True, linecolor='gray'),
yaxis=dict(showgrid=False, zeroline=False, mirror=True, linecolor='gray'))
fig = go.Figure(data=data, layout=layout)
fig.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.