0

我正在使用 matplotlib(启用 LaTex 和 agg 后端)以使用该pcolormesh函数显示流体动力学模拟。系统:Ubuntu 16.04 Python:Python 2.7.12 Matplotlib:1.5.1-1ubuntu1 我还在添加额外的轴,twinx twiny在保存 ~300 png 图像后,我在处理标题时遇到指向无效 dvi 转换命令的崩溃。我总是pylab.close("all")在每次保存过程后关闭我的身材。

pylab.rc('text', usetex=True)
pylab.rc('text.latex', preamble=[r"\usepackage{amsmath}", r"\usepackage{amssymb}", r"\usepackage[alsoload=astronomy]{siunitx}"])

pylab.close("all")
f, ax = pylab.subplots(1)
cmap = pylab.cm.jet
cmap.set_bad('w',1.)
if in logquantity:
    plot = ax.pcolormesh(x, y, quantity , vmax=maxvalue, vmin=minvalue, norm=LogNorm(vmax= maxvalue, vmin = minvalue), cmap=cmap)
else:
    plot = ax.pcolormesh(x, y, quantity, vmax=maxvalue, vmin=minvalue, cmap=cmap)
ax.set_title("Title")
ax.set_aspect("equal")
ax.set_xscale("log")
ax.grid()
...<More Formatting stuff>
ax2 = ax.axes.twiny()
ax3 = ax.twinx()
...<Formatting labels, setting scales etc>
pylab.savefig("test.png", dpi = 800, bbox_inches='tight')
pylab.close("all")

pylab.savefig("test.png", dpi = 800, bbox_inches='tight')
  File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 689, in savefig
    fig.canvas.draw_idle()   # need this if 'transparent=True' to reset colors
  File "/usr/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 2026, in draw_idle
    self.draw(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 474, in draw
    self.figure.draw(self.renderer)
  File "/usr/lib/python2.7/dist-packages/matplotlib/artist.py", line 61, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1159, in draw
    func(*args)
  File "/usr/lib/python2.7/dist-packages/matplotlib/artist.py", line 61, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 2324, in draw
    a.draw(renderer)
  File "/usr/lib/python2.7/dist-packages/matplotlib/artist.py", line 61, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/text.py", line 792, in draw
    mtext=mtext)
  File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 253, in draw_tex
    Z = texmanager.get_grey(s, size, self.dpi)
  File "/usr/lib/python2.7/dist-packages/matplotlib/texmanager.py", line 583, in get_grey
    pngfile = self.make_png(tex, fontsize, dpi)
  File "/usr/lib/python2.7/dist-packages/matplotlib/texmanager.py", line 524, in make_png
    'dvipng: \n\n' % dvifile + report)
RuntimeError: dvipng was not able to process the following file:
$HOME/.cache/matplotlib/tex.cache/2664bc1e879cb69289e1663e63a1c713.dvi
Here is the full report generated by dvipng:

No dvipng error report available.

如果我检查提到的 .cache 位置,我可以完美地找到提到的 dvi 文件。如果我在它上面使用 dvipng,我会得到它应该放在图中的完美正确渲染的标题。我假设某种缓存/缓冲区已满。如果它只涉及使用 plot、semilogy、semilogx 和 loglog 的线图,我会在更多数量的图像后得到这个错误。如果任何人认为它们与此问题相关,我还可以提供格式详细信息(或任何其他附加信息)。

提前感谢您的回答:-)

编辑: 字符串是$\rho$$\left[6.96e-20 \frac{\si{\gram}}{\si{\centi \meter \cubed}}\right]$, $t =\num{0.00e+00}\text{y}$, $n_R = \num{300}$, $n_{\varphi} = \num{50}$, $n_z = \num{401},\ [C.L.] = 1.14e+02\text{pc}$

缓存文件的 PNG 版本 这是我将缓存文件复制到另一个位置并使用 dvipng 手动将其转换为 png 的结果。

这个问题并不特定于这个情节。任何情节都可能发生。无论前 300 个地块是什么,它都可以正常工作。它并不总是崩溃的同一个情节。这就是研究问题的问题之一。有一个循环遍历所有数量,然后调用函数进行绘图

for quantityname in quantities:
    quantitydict = quantities[quantityname]
    quantity = quantitydict["data"]

每个时间步长有 18 个这样的数量。EDIT2(更多信息)当运行它的机器没有太多可用的主内存(低于 10GB,脚本在运行时使用大约 1GB)时,错误发生的频率更高。此外,有时表现不同。它给出了一个 LaTeX 错误。之前在运行中创建的所有绘图都可以正常工作,我复制该行并在 LaTeX 中编译它,我得到了正确的结果。错误信息:

    pylab.savefig("test.png", dpi = 800, bbox_inches='tight')
  File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 688, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1565, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 2180, in print_figure
    **kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 527, in print_png
    FigureCanvasAgg.draw(self)
  File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 474, in draw
    self.figure.draw(self.renderer)
  File "/usr/lib/python2.7/dist-packages/matplotlib/artist.py", line 61, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1159, in draw
    func(*args)
  File "/usr/lib/python2.7/dist-packages/matplotlib/artist.py", line 61, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 2324, in draw
    a.draw(renderer)
  File "/usr/lib/python2.7/dist-packages/matplotlib/artist.py", line 61, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/text.py", line 749, in draw
    bbox, info, descent = textobj._get_layout(renderer)
  File "/usr/lib/python2.7/dist-packages/matplotlib/text.py", line 361, in _get_layout
    ismath=ismath)
  File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 229, in get_text_width_height_descent
    renderer=self)
  File "/usr/lib/python2.7/dist-packages/matplotlib/texmanager.py", line 675, in get_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "/usr/lib/python2.7/dist-packages/matplotlib/texmanager.py", line 422, in make_dvi
    report))
RuntimeError: LaTeX was not able to process the following string:
'CFL $\\\\Delta t_\\\\text{min}$$\\\\left[4.65e+05 \\\\text{yrs}\\\\right]$, $t =\\\\num{3.80e+03}\\\\text{y}$, $n_R = \\\\num{300}$, $n_{\\\\varphi} = \\\\num{50}$, $n_z = \\\\num{401},\\\\ [C.L.] = 1.14e+02\\\\text{pc}$'
Here is the full report generated by LaTeX: 

No latex error report available.
4

0 回答 0