ezdxf和Matplotlib如何增加线宽
ezdxf and Matplotlib how to increase line thickness
我正在将 DXF 文件转换为下面的 PNG,但我想增加 line
厚度。
现在的线条大约是 1 像素宽,我希望能够将它们放大 5 倍。
我试过来自不同地方的解决方案,例如:
mpl.rcParams['lines.linewidth'] = 5 # set the value globally
mpl.rcParams['patch.linewidth'] = 5 # set the value globally
mpl.rcParams['hatch.linewidth'] = 5 # set the value globally
mpl.rcParams['axes.linewidth'] = 5 # set the value globally
我尝试过的其他解决方案列表:
1.
fig = plt.figure(linewidth=5)
2.
for ln in ax.lines:
ln.set_linewidth(5)
3.
for axis in ['top','bottom','left','right']:
ax.spines[axis].set_linewidth(5)
4.
[i.set_linewidth(5) for i in ax.spines.itervalues()]
但我没有任何东西可以正常工作。
这是一个工作示例:
main.py
from ezdxf.addons.drawing.matplotlib import MatplotlibBackend
from ezdxf.addons.drawing import Frontend, RenderContext
import ezdxf
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['lines.linewidth'] = 5 # set the value globally
mpl.rcParams['patch.linewidth'] = 5 # set the value globally
mpl.rcParams['hatch.linewidth'] = 5 # set the value globally
mpl.rcParams['axes.linewidth'] = 5 # set the value globally
dxffilepath = 'GT-001.DXF'
save_to = 'test.png'
def convert_dxf2img(path, save_to, img_format, img_res):
doc = ezdxf.readfile(path)
msp = doc.modelspace()
auditor = doc.audit()
if len(auditor.errors) != 0:
return
else:
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
ctx = RenderContext(doc)
ctx.set_current_layout(msp)
ctx.current_layout.set_colors(bg='#FFFFFF')
out = MatplotlibBackend(ax)
Frontend(ctx, out).draw_layout(msp, finalize=True)
fig.savefig(save_to, dpi=img_res)
plt.close(fig)
convert_dxf2img(dxffilepath, save_to, img_format='.png', img_res=300)
线条太细了,我想把它们粗5倍。有什么办法吗?
我得到的输出:
我正在将 DXF 文件转换为下面的 PNG,但我想增加 line
厚度。
现在的线条大约是 1 像素宽,我希望能够将它们放大 5 倍。
我试过来自不同地方的解决方案,例如:
mpl.rcParams['lines.linewidth'] = 5 # set the value globally
mpl.rcParams['patch.linewidth'] = 5 # set the value globally
mpl.rcParams['hatch.linewidth'] = 5 # set the value globally
mpl.rcParams['axes.linewidth'] = 5 # set the value globally
我尝试过的其他解决方案列表:
1.
fig = plt.figure(linewidth=5)
2.
for ln in ax.lines:
ln.set_linewidth(5)
3.
for axis in ['top','bottom','left','right']:
ax.spines[axis].set_linewidth(5)
4.
[i.set_linewidth(5) for i in ax.spines.itervalues()]
但我没有任何东西可以正常工作。
这是一个工作示例:
main.py
from ezdxf.addons.drawing.matplotlib import MatplotlibBackend
from ezdxf.addons.drawing import Frontend, RenderContext
import ezdxf
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['lines.linewidth'] = 5 # set the value globally
mpl.rcParams['patch.linewidth'] = 5 # set the value globally
mpl.rcParams['hatch.linewidth'] = 5 # set the value globally
mpl.rcParams['axes.linewidth'] = 5 # set the value globally
dxffilepath = 'GT-001.DXF'
save_to = 'test.png'
def convert_dxf2img(path, save_to, img_format, img_res):
doc = ezdxf.readfile(path)
msp = doc.modelspace()
auditor = doc.audit()
if len(auditor.errors) != 0:
return
else:
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
ctx = RenderContext(doc)
ctx.set_current_layout(msp)
ctx.current_layout.set_colors(bg='#FFFFFF')
out = MatplotlibBackend(ax)
Frontend(ctx, out).draw_layout(msp, finalize=True)
fig.savefig(save_to, dpi=img_res)
plt.close(fig)
convert_dxf2img(dxffilepath, save_to, img_format='.png', img_res=300)
线条太细了,我想把它们粗5倍。有什么办法吗?
我得到的输出: