Skip to content
Advertisement

Matplotlib: unspecified ticklabels appear after manually setting them

I am currently using python 3.8.3 with matplotlib 3.2.2. I want to automatically set the y-ticklabels of my plot after log transforming them. So I have written a small list comprehension that automatically generates the y-ticks, which I set simultaneously as location and label.

JavaScript

If i execute the code seen above, the y-ticklabel list looks like this:

JavaScript

Which is as I expected it to be, but in my plot two additional y-ticklabel appear: picture of plot with additional ticklabels

picture of plot with additional ticklabels

They do not appear if I use different datapoints (here for example, y data is squared, X data is the same, and tick labels are exactly as the code set them to be):

picture of plot without additional ticklabels

picture of plot without additional ticklabels

Does anybody know why they appear using the original dataset and not when the y data is squared? Thanks in advance for your time and help in this matter!

Advertisement

Answer

There are bunch of things i can suggest to format the y-axis ticks. Refer below example(I have modified your code a bit to remove unnecessary things). I think those were minor ticks and you can turn them off using ax.minorticks_off().

Below is your modified example .

JavaScript

Output Image:

enter image description here

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement