如何禁用绘图中的插值?

问题描述 投票:0回答:1

我有类似以下内容:

    fig.add_layout_image(
        dict(
            source=prefix_webp + base64.b64encode(webp_data).decode("utf-8"),
            xref='x', yref='y',  # Reference subplot axes
            x=0, y= 1,  # Position in subplot grid
            sizex=1, sizey=1,
            xanchor='left', yanchor='top',
            sizing='contain',  # Ensure it fits within the given size
        ),
        row=row, col=col
    )

正弦图像具有少量像素。如果我将图形保存为 PDF,图像将被像素化,这正是我想要的,因为它实际上代表一些数据,我想看到每个像素的确切边缘。

但是,如果我在浏览器中显示它或将其另存为html。图像似乎经过插值并且变得平滑。

我想知道如何在情节中禁用它

尝试通过模板添加CSS并没有真正起作用

html_template = '''
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Plotly Layout Image Example</title>
    <style>
        /* Custom CSS to apply pixelated rendering to images */
        img {
            image-rendering: pixelated;
        }
    </style>
</head>
<body>

    <h1>Plotly Layout Image Example</h1>
    <!-- This is where the Plotly figure will be inserted -->
    {{ fig | safe }}

</body>
</html>
'''

plotly_html = fig.to_html(full_html=False)

from jinja2 import Template
template = Template(html_template)
html_output = template.render(fig=plotly_html)
with open(os.path.expanduser('test-css.html'), 'w') as file:
    file.write(html_output)
plotly
1个回答
0
投票

终于成功了。我们需要将图像标签识别为

svg image

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Plotly Layout Image Example</title>
    <style>
        /* Custom CSS to apply pixelated rendering to images */
        svg image {
            image-rendering: pixelated;
        }
    </style>
</head>
<body>

    <h1>Plotly Layout Image Example</h1>
    <!-- This is where the Plotly figure will be inserted -->
    {{ fig | safe }}

</body>
</html>

这个模板终于可以用了

© www.soinside.com 2019 - 2024. All rights reserved.