I am trying to plot 3 series with 2 on the left y-axis and 1 on the right using secondary_y
, but it’s not clear to me how to define the right y-axis scale as I did on the left with ylim=()
.
I have seen this post: Interact directly with axes
… but once I have:
import matplotlib.pyplot as plt
df = pd.DataFrame(np.random.randn(10,3))
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(df.index,df.iloc[:,[0,2]])
ax2.plot(df.index, df.iloc[:,2])
plt.show()
doesn't produce anything at all. I am using:
- Spyder 2.3.5.2
- python: 3.4.3.final.0
- python-bits: 64
- OS: Windows
- OS-release: 7
- pandas: 0.16.2
- numpy: 1.9.2
- scipy: 0.15.1
- matplotlib: 1.4.3
I found these links helpful:
You can do this without directly calling ax.twinx():
Note: Only tested in Pandas 19.2
You need to use
set_ylim
on the appropriate ax.For example:
Also, reviewing your code, it appears that you are specifying your
iloc
columns incorrectly. Try: