2 回答
TA贡献1757条经验 获得超8个赞
尝试将可见性设置为 false 而不是使用“off”:
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
def plot_net(line, dot, name = "test.png"):
mpl.rcParams['agg.path.chunksize'] = 10000
fig = plt.figure(figsize = (5, 5), frameon = False)
axiss = fig.add_axes([0, 0, 1, 1])
axiss.set_aspect('equal', adjustable = 'datalim')
axiss.get_yaxis().set_visible(False)
axiss.get_xaxis().set_visible(False)
axiss.scatter(dot[:, 0], dot[:, 1], color = 'red', s = 4)
axiss.plot(line[:, 0], line[:, 1], 'r.', ls = '-', color = '#0063ba', markersize = 2)
plt.savefig(name, bbox_inches = 'tight', pad_inches = 0, dpi = 200)
plt.close()
a = np.random.rand(4, 2)
b = np.random.rand(4, 2)
plot_net(a, b, name = "c:/temp/test2.png")
TA贡献1802条经验 获得超4个赞
TA贡献1890条经验 获得超9个赞
看起来它与您对“轴”的定义有关。如果你绕过它它会起作用:
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
def plot_net(line, dot, name = "test.png"):
mpl.rcParams['agg.path.chunksize'] = 10000
fig = plt.figure(figsize = (5, 5), frameon = False)
plt.axes().set_aspect('equal', adjustable = 'datalim')
plt.scatter(dot[:, 0], dot[:, 1], color = 'red', s = 4)
plt.plot(line[:, 0], line[:, 1], 'r.', ls = '-', color = '#0063ba', markersize = 2)
plt.axis('off')
plt.savefig(name, bbox_inches = 'tight', pad_inches = 0, dpi = 200)
plt.close()
a = np.random.rand(4, 2)
b = np.random.rand(4, 2)
plot_net(a, b)
添加回答
举报