0

我正在将 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()]

但我没有什么可以正常工作。

这是一个工作示例:

主文件

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倍。有没有办法做到这一点?

我得到的输出: 输出

4

1 回答 1

1

在 ezdxf v0.15 的下一个版本中,可以对后端进行扩展控制,PyPI已经提供了稳定的 alpha 版本。

将线宽缩放 5 倍:

    ...
    out = MatplotlibBackend(ax, params={"lineweight_scaling": 5})
    ...

此处记录了更多后端选项,并且该params函数也支持该qsave()参数。

于 2020-11-05T03:40:30.510 回答