这里有一个想法:
import matplotlib.pyplot as plt
import numpy as np
runoff = np.array([1,4,5,6,7,8,9])
precipitation = np.array([4,5,6,7,3,3,7])
fig, ax = plt.subplots()
# x axis to plot both runoff and precip. against
x = np.linspace(0, 10, len(runoff))
ax.plot(x, runoff, color="r")
# Create second axes, in order to get the bars from the top you can multiply
# by -1
ax2 = ax.twinx()
ax2.bar(x, -precipitation, 0.1)
# Now need to fix the axis labels
max_pre = max(precipitation)
y2_ticks = np.linspace(0, max_pre, max_pre+1)
y2_ticklabels = [str(i) for i in y2_ticks]
ax2.set_yticks(-1 * y2_ticks)
ax2.set_yticklabels(y2_ticklabels)
plt.show()
![enter image description here](https://istack.dev59.com/nfti2.webp)
当然,有更好的方法来实现这个功能,而且从 @Pierre_GM 的回答中看来,已经有现成的更好的方式了。