python-3.x - Matplotlib 绘图在另存为 pdf 时失去透明度
问题描述
pdf
以matplotlib 格式保存绘图时,不会保留透明度。我已经尝试过,在svg
这里它确实如此,因此它能够以透明度保存图形。
我已经看到Matplotlib中的解决方案等解决方案在保存为 .pdf 时会失去透明度,但将轴设置为光栅化对我不起作用。这是 matplotlib 中的错误还是我做错了什么?
注意:我使用的是 python 3.9.2
代码
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2*np.pi)
y = np.cos(x)
fig, ax = plt.subplots(figsize=(10,6))
ax.plot(x, y, '--')
fig.savefig('example.pdf', transparent=True, bbox_inches='tight')
fig.savefig('example.svg', transparent=True, bbox_inches='tight')
解决方案
推荐阅读
- python-3.x - 使用 PyQt5 Pixmap 和文本拖放 QLabels
- python - 使用烧瓶模板渲染 HTML 时,绘图会被弯曲
- php - 在 WordPress 中的哪里添加我的 PHP 表单处理程序文件?
- ios - Swift:无法使用实现 Objectmappers Mappable 的自定义类返回类型覆盖方法
- jenkins - Groovy - 如何正则表达式具有子字符串 QA 的字符串?
- perl - 使用触发器运算符跟踪基于缩进的状态
- office-ui-fabric - Office UI Fabric 组件定义之间的一致性
- wordpress - 第一次点击后手风琴标签不打开
- laravel - 在 laravel 中获取外键数据
- recursion - 递归 vue 组件的延迟加载