有没有办法改变 ezdxf 中的背景颜色?
Is there a way to change the background color in ezdxf?
我想更改照片的背景颜色,因为它不清晰我尝试更改 matplotlib
背景的图,但是没有用
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')
drawing
add-on 仍处于测试阶段,但您可以尝试将背景设置为白色:
if len(auditor.errors) == 0:
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
ctx = RenderContext(doc)
# --- add this lines ---
ctx.set_current_layout(msp)
ctx.current_layout_properties.set_colors(bg='#FFFFFF')
# --- add this lines ---
out = MatplotlibBackend(ax)
Frontend(ctx, out).draw_layout(msp, finalize=True)
fig.savefig('your.png', dpi=300, facecolor = 'black', edgecolor = 'black')
尝试覆盖 MODEL_SPACE_BG_COLOR 变量:
ezdxf.addons.drawing.properties.MODEL_SPACE_BG_COLOR = "#FFFFFF"
我想更改照片的背景颜色,因为它不清晰我尝试更改 matplotlib
背景的图,但是没有用
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')
drawing
add-on 仍处于测试阶段,但您可以尝试将背景设置为白色:
if len(auditor.errors) == 0:
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
ctx = RenderContext(doc)
# --- add this lines ---
ctx.set_current_layout(msp)
ctx.current_layout_properties.set_colors(bg='#FFFFFF')
# --- add this lines ---
out = MatplotlibBackend(ax)
Frontend(ctx, out).draw_layout(msp, finalize=True)
fig.savefig('your.png', dpi=300, facecolor = 'black', edgecolor = 'black')
尝试覆盖 MODEL_SPACE_BG_COLOR 变量:
ezdxf.addons.drawing.properties.MODEL_SPACE_BG_COLOR = "#FFFFFF"