I am working with a list of numbers, where each single digit number has been formatted to have 2 characters, i.e. ' 9', '20', ' 1' and etc.
My issue is when I turn the list into a string, via str.join, the new string keeps the spacing correct when I print, but for plotting it doesn't. I could just add a leading zero to keep the integrity, but for aesthetic purposes I want to keep single digit numbers.
I have 2 of these lists that have been converted to strings, with different numbers, so when they vary, they start to stray from one another. Is it possible to keep the spacing integrity like print does, for plotting text.
The text prints like this (spacing perfect, same width):
1 3 4 2 2 4 4 2 1 1 1 1 1 1 6 14 11 16 16 10 5 4 3 3 6
2 4 4 4 3 5 5 3 1 2 1 1 1 3 14 18 13 21 20 12 10 6 4 4 8
But plots like this (where the overall spacing and width is off).
1 3 4 2 2 4 4 2 1 1 1 1 1 1 6 14 11 16 16 10 5 4 3 3 6
2 4 4 4 3 5 5 3 1 2 1 1 1 3 14 18 13 21 20 12 10 6 4 4 8
I am aware of using spacing between characters in join, but here is some of my code:
q = [1, 3, 4, 2, 2, 4, 4, 2, 1, 1, 1, 1, 1, 1, 6, 14, 11, 16, 16, 10, 5, 4, 3, 3, 6]
q1 = [2, 4, 4, 4, 3, 5, 5, 3, 1, 2, 1, 1, 1, 3, 14, 18, 13, 21, 20, 12, 10, 6, 4, 4, 8]
ddd = ['{:2}'.format(x) for x in q]
dddd = ['{:2}'.format(x) for x in q1]
q3 = " ".join(['{:>2}'.format(x) for x in ddd])
q4 = " ".join(['{:>2}'.format(x) for x in dddd])
Pic for reference
Plotting text code:
ax.text(0.035, 0.97, q3, horizontalalignment='left',
verticalalignment='baseline', fontsize=9.5, transform=ax.transAxes)
ax.text(0.035, 0.92, q4, horizontalalignment='left',
verticalalignment='baseline', fontsize=9.5, transform=ax.transAxes)