<p>感谢drYG的回答和aeolus的问题。我有一个类似的问题,由于这个inkscape错误和缺乏一个简单的方法来更改matplotlib中的设置。然而,drYG的答案似乎并不适用于python3。我已经对它进行了更新,并修改了一些可能的拼写错误(与python版本无关)。希望这能为别人节省一些时间,因为我努力弥补我的损失!在</p>
<pre><code>def fixmiterlimit(svgdata, miterlimit = 10):
# miterlimit variable sets the desired miterlimit
mlfound = False
svgout = ""
for line in svgdata:
if not mlfound:
# searches the stroke-miterlimit within the current line and changes its value
mlstring = re.subn(r'stroke-miterlimit:([0-9]+)', "stroke-miterlimit:" + str(miterlimit), line)
#if mlstring[1]: # use number of changes made to the line to check whether anything was found
#mlfound = True
svgout += mlstring[0] + '\n'
else:
svgout += line + '\n'
return svgout
import io, re
imgdata = io.StringIO() # initiate StringIO to write figure data to
# the same you would use to save your figure to svg, but instead of filename use StringIO object
plt.gca()
plt.savefig(imgdata, format='svg', dpi=90, bbox_inches='tight')
imgdata.seek(0) # rewind the data
svg_dta = imgdata.getvalue() # this is svg data
svgoutdata = fixmiterlimit(re.split(r'\n', svg_dta)) # pass as an array of lines
svgfh = open('test.svg', 'w')
svgfh.write(svgoutdata)
svgfh.close()
</code></pre>