pythonezdxf

Is there a way to change the background color in ezdxf?


I want to change the background color of the photo because it's not clear I tried to change the Figure of matplotlib background but it doesn't work

the image


    import matplotlib.pyplot as plt
    import ezdxf
    from ezdxf.addons.drawing import RenderContext, Frontend
    from ezdxf.addons.drawing.matplotlib import MatplotlibBackend
    plt.rcParams["savefig.facecolor"] = 'black'
    plt.rcParams['axes.facecolor'] = 'black'

    doc = ezdxf.readfile("second.dxf")
    msp = doc.modelspace()
    doc.layers.new(name='MyLines', dxfattribs={'linetype': 'DASHED', 'color': 8})


    auditor = doc.audit()


    if len(auditor.errors) == 0:
       fig = plt.figure()
       ax = fig.add_axes([0, 0, 1, 1])
       ctx = RenderContext(doc)
       out = MatplotlibBackend(ax)
       Frontend(ctx, out).draw_layout(msp, finalize=True)
       fig.savefig('your.png', dpi=300, facecolor = 'black', edgecolor = 'black')

Solution

  • try overriding MODEL_SPACE_BG_COLOR variable:
    ezdxf.addons.drawing.properties.MODEL_SPACE_BG_COLOR = "#FFFFFF"