Python 调整散点图matplotlib的大小

Python 调整散点图matplotlib的大小,python,matplotlib,Python,Matplotlib,我有下面的代码,我不能得到正确的大小,以避免数字走出盒子 plt.style.use('bmh') fig, ax = plt.subplots() plt.grid(False) x_coordinates = [0, 1, 0, 1, 2, 0, 2, 1, 2, 3, 0, 3, 1, 3, 2, 3, 4, 0, 4, 1, 4, 2, 4, 3, 4, 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6,

我有下面的代码,我不能得到正确的大小,以避免数字走出盒子

plt.style.use('bmh')
fig, ax = plt.subplots()
plt.grid(False)

x_coordinates = [0, 1, 0, 1, 2, 0, 2, 1, 2, 3, 0, 3, 1, 3, 2, 3, 4, 0, 4, 1, 4, 2, 4, 3, 4, 5, 0, 5, 1, 5, 2,
5, 3, 5, 4, 5, 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6]
y_coordinates = [0, 0, 1, 1, 0, 2, 1, 2, 2, 0, 3, 1, 3, 2, 3, 3, 0, 4, 1, 4, 2, 4, 3, 4, 4, 0, 5, 1, 5, 2, 5,
3, 5, 4, 5, 5, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6]
sync_time = [0, 3.072925, 1.9173166666666666, 2.533416666666666, 4.7773, 5.225908333333335, 4.8926083333333334, 3.912066666666667, 5.712391666666666, 6.717341666666668, 10.300316666666667, 6.0128666666666675, 7.043066666666666, 8.964591666666667, 9.287791666666667, 11.725258333333334, 10.966074999999998, 11.492116666666668, 11.528308333333332, 11.877600000000001, 12.701591666666669, 13.259616666666666, 14.995133333333333, 14.443, 14.52885, 14.187133333333339, 15.297291666666666, 13.737683333333331, 15.980725000000003, 17.736441666666668, 16.238275,
17.658166666666666, 16.34685, 19.338133333333328, 18.430816666666665, 21.322783333333337, 18.429975000000006, 26.312183333333333, 18.317191666666666, 18.445966666666664, 21.733516666666667, 19.684058333333336, 22.7553, 21.526466666666668, 23.974874999999997, 22.005375, 24.95205, 24.330058333333334, 26.26084166666667]

cm = plt.cm.get_cmap('inferno')
sc = plt.scatter(x_coordinates, y_coordinates, c=sync_time, vmin=min(sync_time), vmax=max(sync_time), s=200, cmap=cm)

for x, y, name in zip(x_coordinates, y_coordinates, mote_list) :
    # annotate the points 5 _points_ above and to the left of the vertex
    ax.annotate('{}'.format(name), xy=(y,x), xytext=(5, 5),textcoords='offset points')

cb = plt.colorbar(sc)
cb.set_label("Temps (min)")
plt.yticks([])
plt.xlabel("Sauts")
plt.xticks(range(0, int(square_up)))
plt.savefig("color_test")
plt.clf()
这是获得的结果


有什么想法吗

在保存图形之前,可以检索
fig
实例并使用

my_fig = plt.gcf()
my_fig.set_size_inches(width_in_inches, height_in_inches)
然后继续,并将数字保存为正常值