Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Aligning rotated xticklabels with their respective xticks

import matplotlib.pyplot as plt

x = range(6)
y = [-3, -2, -1, 1, 2, 3]
xlabels = [f'label {i}' for i in x]

fig, ax = plt.subplots()
ax.bar(x, y)

# ha='***' is not enough to visually align labels with ticks 
# use both ha='***' and rotation_mode='anchor'
ax.set_xticks(x, xlabels, rotation=45, ha='right', rotation_mode='anchor')

plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: print in python without using print 
Python :: how to make a checksum to a file python 
Python :: python iterating through a string 
Python :: how to get count by using group by in python 
Python :: how to take date as input in python 
Python :: how to find the speed of a python program 
Python :: slicing in python listing 
Python :: extract nonzero array elements python 
Python :: pandas remove time from date 
Python :: cors flask 
Python :: python download file from url requests 
Python :: pycountry 
Python :: get last 3 in list python 
Python :: if else in list comprehension 
Python :: set permissions role discord.py 
Python :: import ndimage 
Python :: python append csv to dataframe 
Python :: django print query 
Python :: use django taggit in template 
Python :: int to alphabet letter python 
Python :: Python from...import statement 
Python :: coding planets 
Python :: drop row with condition dataframe 
Python :: enter selenium in python 
Python :: lagrange polynomial python code 
Python :: using a dictionary in python 
Python :: how to enter a int in python 
Python :: how to use random tree in python 
Python :: how to terminate subprocess.call in python 
Python :: merge two columns pandas 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =