Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to rotate x-axis labels in Matplotlib

📅 2019-Sep-12 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ matplotlib ⬩ 📚 Archive

X-axis labels in Matplotlib are horizontal by default. If the labels are long strings, then it might appear crowded or overlap with each other.

A common solution for this is to make the labels vertical or rotated at a certain angle:

import matplotlib.pyplot as pyplot
# Plot the graph ... and then
# Rotate X-axis labels anti-clockwise by 30 degrees

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧