在python matplotlib中旋转轴文本 [英] Rotate axis text in python matplotlib

查看:149
本文介绍了在python matplotlib中旋转轴文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何在X轴上旋转文本.这是一个时间戳记,因此随着样本数量的增加,它们越来越近,直到它们重叠.我想将文本旋转90度,以使样本靠得更近,不会重叠.

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.

下面是我所拥有的,除了我不知道如何旋转X轴文本之外,它都可以正常工作.

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)

这篇关于在python matplotlib中旋转轴文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆