Python 调整matplotlib插图中轴标签和轴边界之间的间距

Python 调整matplotlib插图中轴标签和轴边界之间的间距,python,matplotlib,3d,axes,insets,Python,Matplotlib,3d,Axes,Insets,我已经生成了一个网络图形,并将其作为插图添加到matplotlib中生成的图形中: import networkx as nx import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from matplotlib.transforms import Bbox import numpy as np G = nx.gnm_random_graph(n=10, m=15, seed=1) nxpos = nx.

我已经生成了一个网络图形,并将其作为插图添加到matplotlib中生成的图形中:

import networkx as nx
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.transforms import Bbox
import numpy as np

G = nx.gnm_random_graph(n=10, m=15, seed=1)
nxpos = nx.spring_layout(G, dim=3, seed=1)

nxpts = [nxpos[pt] for pt in sorted(nxpos)]
nx_lines = [(nxpts[i], nxpts[j]) for i, j in G.edges()]

# node values
values = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
          [30, 80, 10, 79, 70, 60, 75, 78, 65, 10],
          [1, .30, .10, .79, .70, .60, .75, .78, .65, .90]]
time = [0.0, 0.1, 0.2]  # in seconds

fig, ax = plt.subplots()
ax.plot([1, 2, 3], [1, 2, 3], 'go-', label='line 1', lw=2)

bbox = Bbox.from_bounds(.6, 0, .5, .5)
inax = fig.add_axes(bbox, projection = '3d')

# set angle
angle = 25
inax.view_init(10, angle)

# hide axes, make transparent
inax.grid('off')
inax.set_xlabel('x', labelpad=0, loc='right')
inax.set_ylabel('y', labelpad=0, loc='top')
inax.set_zlabel('z', labelpad=0, loc='right')
inax.set_xticklabels([])
inax.set_yticklabels([])
inax.set_zticklabels([])
    
# plot 3d
seen = set()
for i, j in G.edges():
    x = np.stack((nxpos[i], nxpos[j]))
    inax.plot(*x.T, color='k')
    if i not in seen:
        inax.scatter(*x[0], color='skyblue')
        seen.add(i)
    if j not in seen:
        inax.scatter(*x[1], color = "skyblue")
        seen.add(j)

fig.show()

勾号标签已删除,因此轴和轴标签的边界框之间存在大量空白(请检查上图中的插入轴标签)。为了调整轴边界框和轴标签之间的间距,我尝试在
inax中设置
labelpad=0
。设置标签('x',labelpad=0,loc='right')
。但这并没有删除空格


如何将标签放置在靠近轴边界的位置?

您可以将
labelpad
设置为负值您可以将
labelpad
设置为负值