我想在20x20毫米的图形上创建“L”形黑白结构。每个L形的宽度和长度定义为uw,ul,lw和ll(见代码)。我的理解matplotlib的工作原理是每英寸点数(PPI)为72,线宽为1,形状宽度为1/72英寸。我无法理解当我使用plt.show()并将它们保存在我想要的尺寸(即20x20 mm页面和每个L具有高DPI的确切形状尺寸以便我可以)时,如何使这些数字足够大以便可见当我打开保存的图时查看它)。我的代码是:
import matplotlib.pyplot as plt
import numpy as np
uw = 20e-6 #upper width in meters
ul = 100e-6 #upper length in meters
lw = 20e-6 #lower width in meters
ll = 100e-6 #lower length in meters
w_space = 50e-6 #width spacing for subplots
h_space = 50e-6 #height spacing for subplots
N = 40
coord = [[0,0], [ll,0], [ll,lw], [uw,lw], [uw,ul], [0,ul]]
coord.append(coord[0]) #repeat the first point to create a 'closed loop'
xs, ys = zip(*coord) #create lists of x and y values
fig = plt.figure(num=None, figsize=(0.1, 0.1), dpi=100, facecolor='w', edgecolor='k') #figsize cannot be chosen below 0.1
for i in range(N):
ax = fig.add_subplot(5,10,i+1)
ax.fill(xs,ys,'k',linewidth=1)
plt.axis('off')
plt.subplots_adjust(wspace = w_space, hspace = h_space)
plt.savefig('screenshots/L_shape.png' ,bbox_inches = 'tight', pad_inches = 0, dpi=10000)
plt.show()