본문 바로가기
Python/Python FAQ

Python 축 눈금 라벨 회전, Rotate axis tick labels

by 베타코드 2023. 10. 5.
반응형

질문


I can't figure out how to rotate the text on the X Axis. Its a time stamp, so as the number of samples increase, they get closer and closer until they overlap. I'd like to rotate the text 90 degrees so as the samples get closer together, they aren't overlapping.

Below is what I have, it works fine with the exception that I can't figure out how to rotate the X axis text.

import sys

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import datetime

font = {'family' : 'normal',
        'weight' : 'bold',
        'size'   : 8}

matplotlib.rc('font', **font)

values = open('stats.csv', 'r').readlines()

time = [datetime.datetime.fromtimestamp(float(i.split(',')[0].strip())) for i in values[1:]]
delay = [float(i.split(',')[1].strip()) for i in values[1:]]

plt.plot(time, delay)
plt.grid(b='on')

plt.savefig('test.png')

답변


이렇게 작동합니다:

plt.xticks(rotation=90)
반응형

댓글