0

Labels need to be shifted one place to the right

I wrote code to make a scatter plot. The x-axis ticks were originally 1 - 5 and I did the following to convert the numbers into text:

xLabels = ['V', 'rho_bd', 'lw', 'soc', 'fP']
plt.xticks(sampleId, xLabels, fontname = "Arial",fontsize=12)

Unfortunately, I have the problem shown in the figure, where the labels are on the wrong ticks. The "V" label is missing. It should be where "rho_bd" is. The "rho_bd" labels and the other labels should be moved one place to the right.

I have come across posts here where people have a problem with alignment of rotated bar graph labels to the correct ticks. It seems like that problem can be solved by simply aligning the labels--e.g., "left" instead of "right." That does not seem to be what I'm dealing with. I saw a post a while back (but can't find it again) where someone had this same problem. An answerer referred to some inherent issue with the way labels are anchored in Python. Unfortunately, that is all I recall. If there is another way to do this, I would be grateful to hear it.

I have not posted my entire code because it deals with file input and output and might be confusing. Also, I'm only allowed to provide snippets. If there is anything specific I can add that might be helpful, I would be happy to.

  • 1
    Do you really expect a debug and working solution with 2 lines of codes you have provided? Please read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Sheldore May 21 '20 at 10:37
  • In this case, yes. From previous experience, posting parts of the code that are not relevant is confusing and time-consuming for people. It's a long code that includes a lot of potentially confusing file input and output tasks. Also, I vaguely remember that when looking for a solution to another problem earlier on, I saw a post by someone who mentioned that this particular problem has something to do with the way labels are anchored. I didn't understand it at the time and can't find it again, but got the impression that this is a known problem. I'll try to provide some more explanation. –  May 21 '20 at 10:44
  • [This](https://stackoverflow.com/questions/11244514/modify-tick-label-text) post will help you – Sheldore May 21 '20 at 10:49
  • `plt.xticks([i+1 for i in sampleId], xLabels, ...)` could work. But you should really think about a minimal reproducible example. Remove unrelevant code, but add relevant code to create a stand-alone example. – JohanC May 21 '20 at 10:52
  • Thank you JohanC. Unfortunately, that didn't have any effect. I will try to come up with an example. –  May 21 '20 at 11:01
  • Sheldore, thank you for that. I am going through it and unfortunately, many of the fixes seem similar to what I have currently. I will take a more careful look, but it looks like whatever my problem is is not addressed at the link. –  May 21 '20 at 11:22

0 Answers0