<p>下面是一个为每个系列创建单独y轴的解决方案。我生成了随机数据,这就是为什么图表看起来不同。您可以修改参数,例如下面每个y轴的下限和上限。你知道吗</p>
<pre><code>import matplotlib.pyplot as plt
fig, ax1 = plt.subplots(figsize=(10,10))
ax2 = ax1.twinx()
ax1.plot(GPUDATA.groupby(GPUDATA['Date'].dt.strftime('%Y'))['Price_USD'].mean(),'r', label = 'Avg GPU Prices')
ax1.set_ylabel("Avg GPU Price", color='r', fontsize=20)
ax1.set_ylim(350,600)
ax1.tick_params(axis='y', colors= 'r', labelsize=14)
ax1.tick_params(axis='x', colors= 'k', labelsize=14)
ax2.plot(BITCOINDATA.groupby(BITCOINDATA['Date'].dt.strftime('%Y'))['Open'].mean(), 'b', label = 'Avg Crypto Prices')
ax2.set_ylabel("Avg Crypto Price", color='b', fontsize=20)
ax2.set_ylim(0, 900)
ax2.tick_params(axis='y', colors= 'b', labelsize=14)
lines, labels = ax1.get_legend_handles_labels()
lines2, labels2 = ax2.get_legend_handles_labels()
ax1.legend(lines + lines2, labels + labels2, loc=2, fontsize=20)
ax1.grid(b=False)
ax2.grid(b=False)
plt.title("Yearly Average GPU and Crypto Prices", fontsize=25)
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/zpC1f.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zpC1f.png" alt="enter image description here"/></a></p>