0

I have seen several questions about changing the label pad, and changing the a single x-axis label, but not for changing the label pad for a single x-axis label! I have a graph that I am using to represent a range, and then the user score populates onto it. I want to ensure the score cant be placed on top of the other ticks, so i want to change its pad so that it generates further from the graph while the rest of the labels remain close.

here is an image of said graph: enter image description here

I have tried a few methods for isolating an x index and then adjusting only its pad, but none seem to work. here are some helpful pieces from the code.

'''

xticks = [0,62.5,125,187.5,230,250]
yticks = ['0%', '25%', '50%', '75%', 'Your Score 92%','100%']
mp.xticks(xticks,yticks, rotation = 37, fontsize=15)
mp.yticks([])
ax.tick_params(axis='x', pad=30)
mp.axis('tight')
mp.savefig('HealthyScore.png', bbox_inches='tight', transparent=True)
mp.show()

'''

enter image description here

Nathan
  • 65
  • 5
  • 1
    It seems a bit convoluted to use padding for this. Have you tried setting horizontal alignment to the right? `ha='right'` in `mp.xticks(...)` – Tranbi Jul 06 '23 at 06:19
  • I have not, admittedly I am very new to matplotlib and the only way i could find so far to adjust this distance was to place it on the label pad. could you elaborate a little on how i could try with horizontal alignment and what that does? – Nathan Jul 06 '23 at 20:19
  • `mp.xticks(xticks, yticks, rotation = 37, fontsize=15, ha='right')` will align the tick labels to the right. That way they don't overlap in your example. BTW what you call `yticks` are actually x-labels – Tranbi Jul 07 '23 at 06:29
  • haha yes, i do need to go back and reverse the variables, thank you. And I see, so ha adjusts text and that is helpful, but what i am trying to avoid is when two ticks have very close values and the text populates on top of itself. The 'Your Score' value will be able to change and if it appears near a tick the text will overlap. i have added a second photo to the question to clarify what i am trying to avoid. – Nathan Jul 07 '23 at 16:44

0 Answers0