python - Matplotlib 2.2.2 无法 xkcdify 绘图
问题描述
我将 matplotlib 2.2.2 与 Python 3.5.2 一起使用
当我尝试使用 matplotlib 的 xkcd 函数时,我得到一个正常的图形:
import matplotlib
print(matplotlib.get_cachedir())
print(matplotlib.__version__)
import matplotlib.font_manager
x = [f.name for f in matplotlib.font_manager.fontManager.ttflist if f.name.startswith("Humor")]
print(set(x))
from matplotlib import pyplot as plt
import numpy as np
plt.xkcd(scale=10, length=100, randomness=20)
plt.plot(np.sin(np.linspace(0, 10)))
plt.title('Whoo Hoo!!!')
plt.show()
输出:
/home/thatsme/.cache/matplotlib
2.2.2
{'Humor Sans'}
因此,安装了 Humor Sans,我删除了字体缓存,以防万一,正如其他线程所建议的那样,我增加了 jitter 参数,但仍然没有 xkcdification 的迹象:
奇怪的是,我在 Ubuntu 16.04 和 Windows 10 上将 Eclipse 作为双启动安装,并且 xkcd 功能在两个系统上都失败了。我原以为这些系统之间的 Python 和 Eclipse 安装有很大不同,但我们在这里。
任何想法,可能是什么问题?
Edit: As Hans pointed out this might be a problem specific for matplotlib 2.2.2
Even more bizarre - if I run the same script using with :
without any other changes like
with plt.xkcd(scale=10, length=100, randomness=20):
plt.plot(np.sin(np.linspace(0, 10)))
plt.title('Whoo Hoo!!!')
plt.show()
the output is the expected xkcd figure:
Removing the with :
statement brings back the first figure. The same behaviour again on both Linux and Windows, so seemingly a matplotlib version problem.
Edit: Now that we know it is a temporary, limited bug, back to the main question - How to get rid of the white edgecolor in xkcd
解决方案
This is a bug purely present in matplotlib 2.2. The problem is that the garbage collector is too quick. See this comment and below.
这意味着目前您需要在上下文中使用 xkcd 样式才能使其工作。该问题应在下一个版本中修复。因此,问题中的代码在当前开发版本中按预期工作。
推荐阅读
- aspose.words - 如何在 Aspose.Word 模板中格式化小数位?
- python - 为什么我的神经网络会给出 AttributeError?- “NoneType”对象没有属性“shape”
- javascript - 自动禁止新的不和谐帐户的代码不起作用
- pandas - 通过级别值的组合对具有多索引的 Pandas 数据帧进行切片
- office365 - Office365 中服务事件消息的严重级别是什么
- visual-studio-code - 尝试通过 vs 代码将我的组织连接到 salesforce cli,出现错误:未为此组织启用 REST API
- reactjs - 使用 React js 前端无法显示来自 Firestore 的文档
- regex - 正则表达式匹配除以空格分隔的主题标签之外的所有内容
- ssh - SSH 隧道错误:第一次成功使用后“绑定:地址已在使用”
- sql - 在连接查询中按最新日期排序