Python matplotlib.pyplot.SubPlot内等高线图中没有内联间距
我正在使用matplotlib.pyplot.SubPlot创建一个3x3绘图b/c,它可以轻松共享轴。然后在每个子图中绘制一个等高线图和等高线图。在等高线图中放置文本时,内联_间距仅在最后一个图中正确,否则没有内联_间距。就好像我没有为前8个子情节打开内联文本一样。这是我的密码:Python matplotlib.pyplot.SubPlot内等高线图中没有内联间距,python,matplotlib,inline,contour,subplot,Python,Matplotlib,Inline,Contour,Subplot,我正在使用matplotlib.pyplot.SubPlot创建一个3x3绘图b/c,它可以轻松共享轴。然后在每个子图中绘制一个等高线图和等高线图。在等高线图中放置文本时,内联_间距仅在最后一个图中正确,否则没有内联_间距。就好像我没有为前8个子情节打开内联文本一样。这是我的密码: import numpy as np import matplotlib.pyplot as plt import rfFile, rfMath, rfGeneral plt.ion() de_1 = list(n
import numpy as np
import matplotlib.pyplot as plt
import rfFile, rfMath, rfGeneral
plt.ion()
de_1 = list(np.linspace(0,100,101))
de_2 = list(np.linspace(0,100,101))
gain_2 = np.linspace(0,16,9)
levels = np.linspace(0,100,11)
de = np.array([[x,y] for x in de_1 for y in de_2])
dx = de[:,0]
dy = de[:,1]
xytri = rfGeneral.createTriMesh(dx, dy, 2)
fig, ax = plt.subplots(nrows=3, ncols=3, sharex=True, sharey=True)
ax = ax.flatten()
for ix, g in enumerate(gain_2):
print g
de_tot = [(x*y)/(x + y/rfMath.db2lin(g)) for x in de_1 for y in de_2]
de_tot = np.nan_to_num(de_tot)
cs = ax[ix].tricontourf(xytri, de_tot, levels)
ax[ix].set_title('Gain: {:2.0f} dB'.format(g))
cs1 = ax[ix].tricontour(xytri, de_tot, levels, linewidths=1.5, colors='k')
ax[ix].clabel(cs1, fmt = '%2.0f', fontsize=14, inline=1)
ax[0].set_ylim(min(de_2),max(de_2))
ax[0].set_xlim(min(de_1),max(de_1))
cax = plt.axes([0.93, 0.1, 0.025, 0.8])
fig.colorbar(cs, cax=cax)
ax[7].set_xlabel(r'$\eta_{D1}\,[\%]$',fontdict={'fontsize':20})
ax[3].set_ylabel(r'$\eta_{D2}\,[\%]$',fontdict={'fontsize':20})
fig.suptitle('Total Drain Efficiency', fontsize=24)
plt.subplots_adjust(top=0.9, left=0.075, right=0.9)
如果你发布一个简单的例子,让人们可以立即复制这个问题,这会有所帮助。rf*模块(它们是什么?)使其他人无法运行您的代码,只会混淆问题的原因 也就是说,将
sharex
和sharey
设置为False
可能会解决您的问题。您可以根据数据手动设置x和y限制
我不确定是什么导致了这个问题。也许共享轴会对剪辑路径应用某种变换,这只会使其对最后一个轴有效。在我看来,它像一只虫子
使用共享轴:
没有共享轴:
import numpy as np
import matplotlib.pyplot as plt
X, Y = np.meshgrid(np.arange(-3.0, 3.0, 0.025), np.arange(-3.0, 3.0, 0.025))
fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(8,4), sharex=True, sharey=True,
subplot_kw={'xticks': [], 'yticks': []})
fig.subplots_adjust(hspace=0.05, wspace=0.05)
for ax in axs.flat:
cs = ax.contour(X, Y, X+Y)
ax.clabel(cs, inline=1, fontsize=10)
import numpy as np
import matplotlib.pyplot as plt
X, Y = np.meshgrid(np.arange(-3.0, 3.0, 0.025), np.arange(-3.0, 3.0, 0.025))
fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(8,4), sharex=False, sharey=False,
subplot_kw={'xticks': [], 'yticks': []})
fig.subplots_adjust(hspace=0.05, wspace=0.05)
for ax in axs.flat:
cs = ax.contour(X, Y, X+Y)
ax.clabel(cs, inline=1, fontsize=10)