我想创建一个左右两侧都有多个y轴的图形。
下面的代码生成右侧有多个y轴的图形。我已尝试将rspline设置更改为“离开”,但它无法正常工作。
如何在左侧添加y4?
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import rcParams
%matplotlib inline
x = np.random.rand(20)
y1 = x*5
y2 = x*5 + 0.2
y3 = x*x*3.5 + 0.2*x
y4 = x*5 + 0.2*x
yLimMin = 0
yLimMax = 2.1
lineWidth = 1.0
fontSize = 24
subTitle = ""
plt.rcParams.update({'axes.labelsize': 'small'})
fig = plt.figure(figsize=(21,29.7))
ax11 = fig.add_subplot(411)
subplotAdjustRight = 0.90
mks = 19 # marker step
ax11.plot(x,y1, linestyle='-', linewidth=lineWidth, color = 'k',
marker='*', markevery=11*mks,
label="CO")
ax11.set_ylabel('CO [%]', color='k')
plt.ylim((0,5))
fig.suptitle(subTitle, fontsize = fontSize)
ax11.yaxis.grid()
plt.locator_params(axis='y', nbins=10)
ax12=ax11.twinx()
ax12.plot(x,y2,linestyle='-', linewidth=lineWidth, color='r',
marker='*', markevery=11*mks,
label="CO22")
ax12.set_ylabel('NO [%]', color='r')
plt.ylim((0,10))
plt.locator_params(axis='y', nbins=10)
ax13= ax11.twinx()
rspine = ax13.spines['right']
rspine.set_position(('axes', 1.05))
ax13.set_frame_on(True)
ax13.plot(x,y3,linestyle='-', linewidth=lineWidth, color='m',
marker='*', markevery=11*mks,
label="CO222")
ax13.set_ylabel('O [%] ', color='m')
plt.ylim((0,20))
plt.locator_params(axis='y', nbins=10)
答案 0 :(得分:2)