如何在两个子图上添加次刻度?
我在图表中有两个子图。请问如何在这两个子图的x轴和y轴上添加小刻度?
另外,我想把右边子图的y轴标签放到y轴的右侧,应该怎么做?能帮我解答这两个问题吗?
# Open the figure to plot the Gain variations for this frequencies
fig = plt.figure()
ax = plt.subplot(121) # To show the ascending order
plt.xlabel ('RF Input Power (dBm)', fontsize = 'smaller')
plt.ylabel ('Gain (dB)', fontsize = 'smaller')
tx = plt.title('Gain Vs Ascending RFInput for ' + str(measuredFrequencyUnderTest) + 'MHz', fontsize = 'smaller')
plt.minorticks_on()
ay = plt.subplot(122, xlim = [rfInputMax, rfInputMin], ylim = [-18.0, 30.0]) # To show the descending order
plt.xlabel ('RF Input Power (dBm)', fontsize = 'smaller')
plt.ylabel ('Gain (dB)', fontsize = 'smaller', horizontalalignment = 'left')
ty = plt.title('Gain Vs Descending RF Input for '+ str(measuredFrequencyUnderTest)+ 'MHz', fontsize = 'smaller')
这段代码只在第一个子图上添加了小刻度。即使我在两个子图中都使用了“plt.minorticks_on”这个命令,小刻度在两个子图上也没有出现。
我需要你们的建议。
谢谢你们,
Gopi
1 个回答
2
只需要在坐标轴上调用 minorticks_on()
,而不是在 pyplot
对象上调用:
ax = plt.subplot(121)
#....
ax.minorticks_on()
ay = plt.subplot(122, ...)
#...
ay.minorticks_on()