如何将命令“旋转 xticklabels”链接到 seaborn 图

我正在学习使用 seaborn 绘图的 Pandas 管道方法:大多数东西都可以很容易地用单线链接起来,但是我很难将xticklabel rotations.


怎么做?


代码:


import numpy as np

import pandas as pd


# plotting

import matplotlib.pyplot as plt

import seaborn as sns

%matplotlib inline

names = ['mpg','cylinders', 'displacement','horsepower','weight',

         'acceleration','model_year', 'origin', 'car_name']


url = "http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data"

df = pd.read_csv(url, sep='\s+', names=names)

阴谋

g = ( df.pipe((sns.factorplot, 'data'), x='model_year', y='mpg')

)


for ax in g.axes.flat: 

    plt.setp(ax.get_xticklabels(), rotation=45)

所需骨架:


( df.pipe((sns.factorplot, 'data'), x='model_year', y='mpg')

.set(xlim=(0,90), ylim=(0,80))

.set (xticklabel_rotation = 45)

)

这可能吗?


所需图片:

http://img4.mukewang.com/618a1fca00010caa02720279.jpg

但我得到:

http://img.mukewang.com/618a1fd90001608b02740281.jpg

凤凰求蛊
浏览 304回答 1
1回答

慕的地6264312

你快到了。而不是.set(xticklabel_rotation = 45)你想要.set_xticklabels(rotation=45)import pandas as pdimport seaborn as snsnames = ['mpg','cylinders', 'displacement','horsepower','weight',         'acceleration','model_year', 'origin', 'car_name']url = "http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data"df = pd.read_csv(url, sep='\s+', names=names)(df.pipe((sns.factorplot, 'data'), x='model_year', y='mpg').set_xticklabels(rotation=45))这给了我:
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python