I'm trying to print a set of lines in the same figure, and write on top of the axis, above each line, some text. I use the minimum value of x of each set of data as a position of the text. The code looks like
for i in range(jobs):
ax.text(xmin,1.15, nameid, rotation=45, ha='left', fontsize=tinyfont, color='k', va='center')
When I do something like that, the text is printed - but in the middle of the graph (as it's using the data coordinates):
As I want to print above the axis, I use then transform=ax.transAxes
to print above, as
for i in range(jobs):
ax.text(xmin,1.15, nameid, transform=ax.transAxes, rotation=45, ha='left', fontsize=tinyfont, color='k', va='center')
Although the text move to the correct position, only the first one is being written:
edit: This happens because the position is above the axis limit 1.0. So, for the x position, I'd like to use the data value xmin; For the y, I want a fixed position above the axis. The problem is that I don't know the final x_lim and y_lim beforehand, as I loop over the data and plot the different pieces.
How can I add the text using the x of the data, but in a constant "y" above the axis?
ax.text(xmin, ax.get_ylim()[1], ...)
. You might need to add a small offset to make it look nice. – tmdavison