Could someone explain why text()
takes integer index labels of quarterly["TotalQuestions"]
as x-coordinates even though x-coordinates of ax2
are labels, such as “14Q1” ?
Screen Link:
https://app.dataquest.io/m/469/guided-project%3A-popular-data-science-questions/10/just-a-fad
My Code:
ax1 = quarterly.plot(x="Quarter", y="DeepLearningRate",
kind="line", linestyle="-", marker="o", color="orange",
figsize=(24,12)
)
ax2 = quarterly.plot(x="Quarter", y="TotalQuestions",
kind="bar", ax=ax1, secondary_y=True, alpha=0.7, rot=45)
for idx, t in quarterly["TotalQuestions"].iteritems():
ax2.text(idx, t, str(t), ha="center", va="bottom")
xlims = ax1.get_xlim()
ax1.get_legend().remove()
handles1, labels1 = ax1.get_legend_handles_labels()
handles2, labels2 = ax2.get_legend_handles_labels()
ax1.legend(handles=handles1 + handles2,
labels=labels1 + labels2,
loc="upper left", prop={"size": 12})
for ax in (ax1, ax2):
for where in ("top", "right"):
ax.spines[where].set_visible(False)
ax.tick_params(right=False, labelright=False)```
What I expected to happen
For ax2.text(idx, t, str(t), ha="center", va="bottom")
part, I do not know why text
method takes idx
, integer index labels of quarterly
,as x-coordinates. I though that the positional argument was supposed to take values of Quarter
since x-coordinates of ax2
are defined by Quarter
(not integer).