Zubayer
Zubayer

Reputation: 581

How to show all the labels in matplotlib?

I am trying to display a chart using matplotlib. But my labels are so big that they are overlapping each other. I want to show it cleanly no overlapping. How can I do that? I am now using below code:

import matplotlib.pyplot as plt

x = ['[email protected]' ,'[email protected]', '[email protected]']
y = [10,25,6]

plt.plot(x,y)

plt.xlabel("loginId")
plt.ylabel("times appeared in the data")

plt.title("loginId Graph")
plt.tight_layout()
plt.show()

Upvotes: 0

Views: 342

Answers (1)

Jakub Žitný
Jakub Žitný

Reputation: 992

I tried your example code, and it doesn't seem to be overlapping there. There are many possibilities. One, commonly used, is to rotate the labels.

You can do it like this:

plt.xticks(rotation=45)

There are more ideas in Changing the “tick frequency” on x or y axis in matplotlib? and in reducing number of plot ticks.

I created an example notebook here, feel free to duplicate and play with it.

Upvotes: 1

Related Questions