Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Matplotlib rotated xticklabels

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 :: Write a program that prints #pythoniscool, followed by a new line, in the standard output. Your program should be maximum 2 lines long You are not allowed to use print or eval or open or import sys in your file 
Python :: Creating a donut plot python 
Python :: how to convert python input to int 
Python :: distplot in python 
Python :: convert all colnames of dataframe to upper 
Python :: python see if a number is greater than other 
Python :: declare pandas dataframe with values 
Python :: howe to print all values and keysin d 
Python :: get every item but the last item of python list 
Python :: python cache 
Python :: how to print upto 5 decimal places in python 
Python :: how to prepare independent and dependent variables from dataframe 
Python :: get last n in list python 
Python :: find all regex matches python 
Python :: get keys from dictionary python 
Python :: check if numpy array contains only duplicates 
Python :: python dataclass 
Python :: python is dict 
Python :: python web crawler 
Python :: remove space from string python 
Python :: python tkinter grid 
Python :: planets code 
Python :: django url static 
Python :: delete cell in jupyter notebook 
Python :: python color print 
Python :: python square a number 
Python :: Visualize Decision Tree 
Python :: list to dict python with same values 
Python :: python hasattribute 
Python :: combine df columns python 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =