我想绘制数据框中的两列(一列作为条形图,另一列作为散点图)。我可以使用Matplotlib实现,但我想使用Seaborn。
以下是代码:
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
df = pd.DataFrame({'Announced Year': [2016, 2017, 2018, 2019],
'Amount Awarded': [12978216, 11582629, 11178338, 11369267],
'Number of Awarded': [18, 14, 13, 13]})
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
sns.scatterplot(x="Announced Year", y="Number of Awarded", data=df, ax=ax2)
sns.barplot(x="Announced Year", y="Amount Awarded", data=df, ax=ax1)
fig.tight_layout() # otherwise the right y-label is slightly clipped
plt.title('2016 to 2019 Announcements')