Python图表输出图像大小

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

我正在使用 Python diagrams 模块来创建图表。 我正在生成不同的图表并寻找一种方法来控制 png 输出的大小,即我需要始终具有相同的大小

谢谢你

我尝试使用:

graph_attr = { "size":     "7.75" }

但是它没有按照我想要的方式工作

python diagram
1个回答
0
投票

要在使用 Python 图表模块时控制 PNG 输出的大小,您可以在

size
字典中设置
graph_attr
属性。但是,
size
的值应采用
"width,height"
格式。以下是如何修改代码以设置 PNG 输出的特定尺寸:

from diagrams import Diagram, Cluster

# Define your diagram here
with Diagram("Example Diagram", show=False, outformat="png", graph_attr={"size": "7.75,7.75"}):
    # Add your nodes and edges here
    pass  # Placeholder, replace with your actual diagram elements

在上面的代码中:

  • "7.75,7.75"
    表示 PNG 输出所需的宽度和高度。您可以调整这些值以满足您的要求。
  • 确保将
    pass
    替换为图表的实际元素。

这应该会产生具有指定大小的 PNG 输出。根据需要调整宽度和高度值以获得所需的输出尺寸。

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