我试图使用pyplot为两个不同的模型绘制一个不和谐图,我必须在x轴上使用logscale。问题是2x10⁰的刻度与我为图表设置的刻度重叠。关于如何在右下角和右上角删除2x10⁰的任何想法?
这里是我使用的代码:
import numpy as np
import matplotlib.pyplot as plt
#Random Data
space = [2**(i/100) for i in range(101)]
plot1 = [np.sin(2*np.pi*30*i) for i in space]
plot2 = [np.sin(2*np.pi*60*i) for i in space]
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twiny()
ax1.set_xscale('log')
ax2.set_xscale('log')
ax1.plot(space, plot1,label='Vassilakis - C4 with C4 generated Spec')
ax1.plot(space, plot2,label='Sethares - C4 with C4 generated Spec')
ax1.legend(bbox_to_anchor=(1.04,1), loc="upper left")
ax1.set_title("Dissonance curve for different Models",y=1.08)
ax1.set_xlabel("scale steps")
ax1.set_ylabel("dissonance for Vassilakis method")
steps = [2**(i/8) for i in range(9)]
labels= ['0','1','2','3','4','5','6','7','8']
steps2 = [2**(i/12) for i in range(13)]
labels2= ['0','1','2','3','4','5','6','7','8','9','10','11','12']
ax1.set_xticks(steps)
ax1.set_xticklabels(labels)
ax2.set_xlim(ax1.get_xlim())
ax2.set_xticks(steps2)
ax2.set_xticklabels(labels2)
plt.show()