我在使用matplotlib和pgf-backend
保存数字方面遇到了问题。
如果我有一个轴限制的图(例如X
:[20,70]
; Y
:[0,-50]
)远低于具有最高X
的数据点 - 和Y
- 值(最低数据点:[0,0]
;最高数据点:[150000,-200000]
)始终存在以下错误:
File "<>", line 816, in exportGraphs2
File "C:\Python26\lib\site-packages\matplotlib\pyplot.py", line 561, in savefig
return fig.savefig(*args, **kwargs)
File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 1421, in savefig
self.canvas.print_figure(*args, **kwargs)
File "C:\Python26\lib\site-packages\matplotlib\backend_bases.py", line 2220, in print_figure
**kwargs)
File "C:\Python26\lib\site-packages\matplotlib\backends\backend_pgf.py", line 882, in print_pdf
self._print_pdf_to_fh(fh, *args, **kwargs)
File "C:\Python26\lib\site-packages\matplotlib\backends\backend_pgf.py", line 858, in _print_pdf_to_fh
check_output(cmdargs, stderr=subprocess.STDOUT, cwd=tmpdir)
File "C:\Python26\lib\site-packages\matplotlib\compat\subprocess.py", line 69, in _check_output
raise subprocess.CalledProcessError(retcode, cmd, output=output)
TypeError
:
__init__() got an unexpected keyword argument 'output'
然而,如果轴限制大于或略小于数据点的最大值,则一切正常。
有谁知道问题可能是什么?
修改
这是我的代码的一部分。由于从QTIPlot读取数据非常复杂,因此它只是一个简短的片段。
import matplotlib as mpl
import sys
sys.path.append("..")
mpl.use('pgf')
latex_preamble = {"text.usetex": True,
"pgf.rcfonts": False,
"pgf.preamble": [r"\usepackage{cmbright}",
r"\usepackage{siunitx}",
r"\usepackage{fontspec}",
r"\setmainfont{Calibri}",
r"\usepackage[utf8x]{inputenc}",
r"\usepackage{textgreek}"]}
mpl.rcParams.update(latex_preamble)
import matplotlib.pyplot as plt
mpl.rcParams.update({'font.size': 24})
x = [186691.98079420399, 94747.037718184903, 43238.854190494698, 19067.6709222838, 8804.8960840724703, 4616.3273881164196, 2784.39307777148, 1924.44569810138, 1421.6244001381001, 1044.0988528353901, 738.32026028954704, 499.78345554987698, 325.91902800532, 208.07599600125701, 136.48397798235101, 97.188999849599597, 77.189874321047498, 66.814364230185305, 61.930218121218097, 58.897007608510897, 57.004014967900098, 55.406903357827098, 54.041568494235101, 52.802043730081699, 51.759023715688997, 50.777510655714799, 49.815484593681198, 48.961058456802903, 48.191611656054903, 47.4882902162026, 46.848714837688902, 46.190288085990197, 45.3774348340838, 44.4693505256935, 43.434754403205901, 42.220754480990998, 40.854413497723201, 39.357546952524302, 37.878908712040399, 36.491255819384499, 35.284755433638502, 34.2610953105862, 33.420298363499299, 32.766550165311301, 32.298722787726398, 31.9724893134679, 31.733745041689001, 31.560804411243499, 31.4680666775029]
y = [-225457.06785031699, -151654.317412915, -93620.558383412499, -53880.168115145199, -30116.624926982, -16905.4587130902, -9712.6193383353802, -5810.69026270625, -3678.9706880631902, -2475.8794835536701, -1751.8371788254599, -1253.7787633139801, -901.12220338703003, -643.67630154638596, -454.56954062206199, -318.51086928594498, -223.35257106637999, -156.97451642102101, -112.89935316650001, -82.655897872917393, -61.638224025861199, -46.766272864377299, -36.093957934023599, -28.313379974280299, -22.4321281711178, -17.961980555220599, -14.556781594439601, -11.97682273137, -10.061208825108, -8.6707057874908102, -7.6773295770935901, -7.0721051618041599, -6.7628705905120299, -6.6605343376401303, -6.69407747810377, -6.8113923612978997, -6.8702914807042204, -6.8388590566887899, -6.5692275645203999, -6.1065237236783396, -5.5035760007258503, -4.79953162532468, -4.0671542575787001, -3.3690652676737902, -2.7612664707248298, -2.2359507233406499, -1.77482078896039, -1.44286837047643, -1.1560624817337399]
fig, ax1 = plt.subplots(figsize=(16,12))
p, = ax1.plot(x, y) # really, x and y would be arrays of doubles which are read from QTIPlot
ax1.set_xlabel(unicode("Z'"))
ax1.set_ylabel(unicode("Z''"))
ax1.set_xlim(20,70)
ax1.set_ylim(0,-50)
ax1.set_aspect('equal', adjustable='box')
ax1.tick_params(axis='y', direction = 'out')
ax1.tick_params(axis='x', direction = 'out')
ax1.yaxis.tick_left()
ax1.xaxis.tick_bottom()
plt.savefig("figure.pdf")