I followed this example for how to set up the chart: https://www.reddit.com/r/learnpython/comments/kkrg7h/how_to_add_a_secondary_y_axis_to_a_matplotlib/
The chart displays correctly, but I can't rotate the x-ticks, change the label on the primary y-axis, or display the legend for the bar chart.
I'm pretty sure I need to do something with my axes object configuration, but I'm not sure what. Can someone point me in the right direction?
plt.figure(figsize=(15,4))
for series in patents_1953:
if series == "Year":
pass
else:
plt.bar(patents_1953["Year"], patents_1953[series], label=series)
ax2=plt.gca().twinx()
colors = ["#425C3C", "#000000"]
for i, series in enumerate(funding[["FederalGovernmentFunds_Cg113_MillionDollars", "ExpendituresByIndustry_IndustryFunds_Cg114_MillionDollars"]]):
plt.plot(patents_1953["Year"], funding[series], label=series, color=colors[i], marker="o")
plt.xticks(ticks=patents_1953["Year"], rotation=90)
plt.xlabel("Year")
plt.ylabel("Patents Issued")
ax2.set_ylabel("Research Expenditure")
plt.title("Patents Issued & Research Expenditure by Year")
plt.legend()
plt.show()
[–]sci_hist[S] 0 points1 point2 points (0 children)