我使用Plotly在Python中生成一些线条图。使用如下示例代码:
from plotly import offline as plot, subplots as subplot, graph_objects as go
fig = subplot.make_subplots(rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.01)
trace1 = go.Scatter(x = [1, 2, 3], y = [1, 2, 3])
trace2 = go.Scatter(x = [1, 2, 3], y = [4, 5, 6])
fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 2, 1)
config_test_plot = {'displaylogo': False, 'displayModeBar': False, 'scrollZoom': True}
test_plot_html = plot.plot(fig, output_type='div', include_plotlyjs=False, config= config_test_plot)
我能够得到所需的绘图。然而,我希望能够得到所有的灰度图。我发现所有的默认主题都不是这种类型的。还有什么我可以做的吗
您尚未指定是为整个绘图指定灰色方案,还是仅为线条指定灰色方案。但是为了让事情变得简单,我将假设前者。在这种情况下,我将:
template = 'plotly_white'
,并且n_colors(lowcolor, highcolor, n_colors, colortype='tuple')
为所有线指定灰度李>示例图:
但正如@S3DEV所提到的,使用灰色调色板也是一种可行的方法,这可以通过以下方式实现:
这将非常适合您的用例,只有有限的行数。在这种情况下,您可以使用以下设置:
并获得:
我想这就是你想要的。但是这里一个相当大的缺点是
px.colors.sequential.Greys
中的颜色数量是有限的,我不得不使用一个循环来分配数据的行颜色。和n_colors(lowcolor, highcolor, n_colors, colortype='tuple')
允许您定义起始颜色、结束颜色以及在它们之间缩放的许多颜色,以形成所有线条的完整比例。这也可以让你根据自己的喜好调整颜色的亮度。所以你可以得到这个:……这:
或者这个:
如果您还想尝试这些图形,这里有一个完整的设置:
相关问题 更多 >
编程相关推荐