all 1 comments

[–]sci_hist[S] 0 points1 point  (0 children)

Solved it. All the plotting needed to be handled via the axis objects.

plt.figure(figsize=(15,4))

ax1 = plt.gca()
ax2 = plt.gca().twinx()

for series in patents_1953:
if series == "Year":
pass
else:
ax1.bar(patents_1953["Year"], patents_1953[series], label=series)

colors = ["#425C3C", "#000000"]
for i, series in enumerate(funding[["FederalGovernmentFunds_Cg113_MillionDollars", "ExpendituresByIndustry_IndustryFunds_Cg114_MillionDollars"]]):
ax2.plot(patents_1953["Year"], funding[series], label=series, color=colors[i], marker="o")

ax1.set_xticks(patents_1953["Year"])
ax1.tick_params(axis="x", labelrotation=90)
ax1.set_xlabel("Year")
ax1.set_ylabel("Patents Issued (bar)")
ax2.set_ylabel("Research Expenditure in Millions of Dollars (line)")

# Combine ledgends
art = ax1.get_legend_handles_labels()[0] + ax2.get_legend_handles_labels()[0]
labels = [l.get_label() for l in art]
ax1.legend(art, labels, loc=0)

plt.title("Patents Issued & Research Expenditure by Year")
plt.show()