【问题标题】:Plotly: how to fill the background of a contour plot when the axes have been resized?Plotly:调整轴大小后如何填充等高线图的背景?
【发布时间】:2022-11-14 04:42:14
【问题描述】:

我绘制了两组二维点的等高线图,并希望使用相同的轴比例并排显示每组的分布。

为了绘制分布,我使用go.Histogram2dContour

问题是,当我重新调整坐标轴时,原始等高线图之外的区域(我假设是)是裸露的,并在 Plotly 图的默认背景上显示通常的灰色。结果是绘图中间的一个矩形,里面有等高线图的图像,周围是灰色的。见图片。

有什么办法可以填充剩余的情节,使它看起来更好?某些绘图类型具有connectgaps=True 选项来填补空白,但这似乎不适用于Histogram2dContour 类型(我尝试作为go.Histogram2dContour 的关键字参数以及contours 字典中的值该函数的参数,没有一个被认为是有效的)。

这是我使用的代码的极简版本:


import numpy as np
np_random = np.random.default_rng()
import plotly.graph_objects as go
from plotly.subplots import make_subplots


fixed_range = 100
scatter_set_1 = np_random.normal(scale=85, size=(164, 2))
scatter_set_2 = np_random.normal(scale=26, size=(78, 2))

fig = make_subplots(1, 2, shared_yaxes=True, subplot_titles=['scatter set 1', 'scatter set 2'])

fig.update_yaxes(range=[-fixed_range, fixed_range])
fig.update_xaxes(range=[-fixed_range, fixed_range])

fig.add_trace(go.Histogram2dContour(x=scatter_set_1[:,0],
                                    y=scatter_set_1[:,1],
                                    colorscale='Reds',
                                    showscale=False), 1, 1)
fig.add_trace(go.Histogram2dContour(x=scatter_set_2[:,0],
                                    y=scatter_set_2[:,1],
                                    colorscale='Greens',
                                    showscale=False), 1, 2)



fig.show()

【问题讨论】:

    标签: python plotly plotly-python


    【解决方案1】:

    我认为你最好的选择是:

    fig.update_layout(paper_bgcolor='white',
                      plot_bgcolor='white')
    

    阴谋

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多