python - 无法在 python matplotlib 中设置图形 gid
问题描述
我想在 matplotlib 中设置图形 gid 并将其保存到 svg 文件中。我发现我可以通过调用得到正确的结果,get_gid()
但无法进入 svg 文件。
我使用的测试代码是这样的:
import matplotlib.pyplot as plt
FIGURE_ID = "the_figure"
FIGURE_PATCH_ID = "the_figure_patch"
fig = plt.figure(figsize=(15, 9))
fig.clf()
fig.set_gid(FIGURE_ID)
fig.patch.set_gid(FIGURE_PATCH_ID)
print(fig.get_gid())
print(fig.patch.get_gid())
fig.savefig('id_test.svg', format='svg')
控制台的输出是:
the_figure
the_figure_patch
但是当我打开 svg 文件时,它是这样的:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Created with matplotlib (https://matplotlib.org/) -->
<svg height="648pt" version="1.1" viewBox="0 0 1080 648" width="1080pt" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<style type="text/css">
*{stroke-linecap:butt;stroke-linejoin:round;}
</style>
</defs>
<g id="figure_1">
<g id="the_figure_patch">
<path d="M 0 648
L 1080 648
L 1080 0
L 0 0
z
" style="fill:#ffffff;"/>
</g>
</g>
</svg>
这证明补丁 gid 已更改,但图形 gid 仍然存在。请帮我弄清楚我的幼稚问题!先感谢您!
解决方案
推荐阅读
- sctp - SCTP_PRIMARY_ADDR 和 SCTP_SET_PEER_PRIMARY_ADDR 选项的 Setsockopt 问题
- maven - 运行maven依赖时如何排除项目内依赖:go-offline
- angular - 我需要将 mat-button-toogle 更改为单选按钮?
- laravel - Laravel 6路线未定义
- precision - 当与推荐项目的相关性是二进制形式时,我们可以使用 NDCG 作为推荐系统指标吗?
- c# - 如何在 RestSharp 中将 json 文件数据解析为请求参数?
- bash - bash 不能用 or 语句比较字符串
- flutter - 如何在动态列表视图中导航到下一页 - Flutter
- android - 在 Flutter WebView 中检查连接并强制刷新
- html - 如何以较低的字体显示子菜单内容?