Why use index labels instead of x-coordinates' labels?

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:

My Code:

ax1 = quarterly.plot(x="Quarter", y="DeepLearningRate",
                    kind="line", linestyle="-", marker="o", color="orange",

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()


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.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).

Hi @tokeihananda,

In case you are still interested with this topic.
For your first question, I think by using text() we’re going to take the number from quarterly['TotalQuestions'] and put it on the table so we can see the exact number.
You might want to refer to this documentation


1 Like