我想正确旋转matplotlib阶梯图。首先,我交换了x和y轴并翻转了y轴。然后我重新绘制了阶梯图。但是,在右边的图片中,步进线(蓝色)的方向不如所期望的那样,并且红色的阶梯线是左边图片的叠加旋转图像。以下是我的代码:
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(14)
y = np.sin(x / 2)
fig, (ax, bx) = plt.subplots(nrows=1, ncols=2, figsize=(11.5, 5.5))
fig.subplots_adjust(left=0.08, bottom=0.13, top=0.98, right=0.97, wspace=0.2, hspace=0.0)
ax.step(x, y, where='mid', c='r')
ax.plot(x, y, 'o--', color='grey', alpha=0.3)
bx.invert_yaxis()
bx.step(y, x, where='pre', c='b')
bx.plot(y, x, 'o--', color='grey', alpha=0.3)
plt.show()
我想制作如右图所示的红色步进图。如何实现?
plot_step_invert_mid(y, x, "ro-")
将无法在所需位置显示标记。 - nonin