代码如下import numpy as np
import matplotlib.pyplot as plt
#构造数据
N = 10
ind = np.arange(N)
bars = np.random.randn(N)
t = np.arange(0.01, 10.0, 0.01)
#新建左侧纵坐标画板
fig, ax1 = plt.subplots()
#画柱状图
ax1.bar(ind, bars, alpha=0.3)
ax1.set_xlabel('$x$')
#显示左侧纵坐标
ax1.set_ylabel('bar', color='b')
[tl.set_color('b') for tl in ax1.get_yticklabels()]
#新建右侧纵坐标画板
ax2 = ax1.twinx()
#画曲线
ax2.plot(t, np.sin(0.25*np.pi*t), 'r-')
#显示右侧纵坐标
ax2.set_ylabel('sin', color='r')
[tl.set_color('r') for tl in ax2.get_yticklabels()]
plt.show()
SofaSofa数据科学社区DS面试题库 DS面经
×
Warning
您确定要删除本贴么?所有相关回复也会被一并删除并且无法恢复。
取消
确定删除
kym1990
-09-23 13:05