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)
添加回答
舉報