for p in ax.patches:
# # bar
# ax.annotate(np.round(p.get_height(), decimals=2),
# (p.get_x() + p.get_width() / 2., p.get_height()),
# ha='center',
# va='center',
# xytext=(0, 10),
# textcoords='offset points')
# barh
ax.annotate(np.round(p.get_width(), decimals=4),
(p.get_x() + p.get_width(), p.get_y()),
# ha='center',
# va='center',
xytext=(2, -10),
textcoords='offset points')
The above code comment style is not as Pythonic as the below one:
for p in ax.patches:
# # bar
# ax.annotate(np.round(p.get_height(), decimals=2),
# (p.get_x() + p.get_width() / 2., p.get_height()),
# ha='center',
# va='center',
# xytext=(0, 10),
# textcoords='offset points')
# barh
ax.annotate(np.round(p.get_width(), decimals=4),
(p.get_x() + p.get_width(), p.get_y()),
# ha='center',
# va='center',
xytext=(2, -10),
textcoords='offset points')
Let it be a single line code comment or a block code comment, when we use the shortcut (e.g. Ctrl + /
on windows), the #
should be indented the same amount as the code line, not be placed at the start of the line.