我试图绘制matplotlib条形图,左边有一个y轴,右边有另一个y,有一个共同的x轴。范围列在x轴上。 Perc列位于左侧y轴上,count列位于右侧y轴上。请告知如何继续。
import numpy as np
import pandas as pd
import seaborn as sbn
import matplotlib.pyplot as plt
fig = plt.figure()
ax = td['perc'].plot(kind="bar", alpha=0.7)
plt.xticks(td['ranges'].tolist())
ax2 = ax.twinx()
ax2.plot(ax.get_xticks(),td['count'],marker='o', c='navy', linewidth=4)
我收到以下错误。
<ipython-input-24-c1d398c0d012> in <module>()
7 fig = plt.figure()
8 ax = td['perc'].plot(kind="bar", alpha=0.7)
----> 9 plt.xticks(td['ranges'].tolist())
10 ax2 = ax.twinx()
11 ax2.plot(ax.get_xticks(),td['count'],marker='o', c='navy', linewidth=4)