gpt4 book ai didi

python - matplotlib mathtext 的奇怪输出

转载 作者:行者123 更新时间:2023-11-28 22:57:00 24 4
gpt4 key购买 nike

我尝试使用 mathtext 来获取经过特殊渲染的图形标题,但失败了。而不是我的测试标题,它只是打印了一些神秘的字符。我做错了什么?

  • 操作系统:Fedora release 18 (Spherical Cow)
  • Python 和 matplotlib 是通过 yum 从官方仓库安装的

这是(完整)代码:

import sys
print sys.version # prints:
# 2.7.3 (default, Aug 9 2012, 17:23:57)
# [GCC 4.7.1 20120720 (Red Hat 4.7.1-5)]
import matplotlib
print matplotlib.__version__ # prints:
# 1.2.0

import matplotlib.pyplot as plt
plt.plot([1,5])
plt.title(r"$1.2345$")
plt.show()

这是输出图像: strange title rendering

最佳答案

如果您使用的是 RedHat、CentOS 或其他 Fedora 衍生产品,您可能会看到此处描述的错误:https://bugzilla.redhat.com/show_bug.cgi?id=562421

尝试安装“stix”字体包(在 CentOS/RedHat 上是“stix-fonts”)。删除您的 ~/.matplotlib/fontlist.cache 文件。接下来,重新运行系统的字体缓存脚本,可能是“fc-cache -f -s -v”。

现在,更改 matplotlibrc 设置(通过 ~./matplotlib/matplotlibrc 文件或与脚本位于同一目录中的 matplotlibrc 文件),如下所示:

mathtext.fontset : stix 
mathtext.fallback_to_cm : True
mathtext.default : it

我很想知道这是否适合你。

关于python - matplotlib mathtext 的奇怪输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14715679/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com