如何在Seaborn的facetgrid中设置可读的xticks? [英] how to set readable xticks in seaborn's facetgrid?

查看:144
本文介绍了如何在Seaborn的facetgrid中设置可读的xticks?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有seaborn的facetgrid的数据框图:

i have this plot of a dataframe with seaborn's facetgrid:

import seaborn as sns
import matplotlib.pylab as plt
import pandas
import numpy as np

plt.figure()
df = pandas.DataFrame({"a": map(str, np.arange(1001, 1001 + 30)),
                       "l": ["A"] * 15 + ["B"] * 15,
                       "v": np.random.rand(30)})
g = sns.FacetGrid(row="l", data=df)
g.map(sns.pointplot, "a", "v")
plt.show()

seaborn绘制了所有xtick标签,而不是仅仅选择了一些标签,这看起来很可怕:

seaborn plots all the xtick labels instead of just picking a few and it looks horrible:

是否可以自定义它,以便在x轴上绘制每个第n个刻度,而不是全部绘制?

Is there a way to customize it so that it plots every n-th tick on x-axis instead of all of them?

推荐答案

seaborn.pointplot不是此绘图的正确工具.但是答案很简单:使用基本的matplotlib.pyplot.plot函数:

The seaborn.pointplot is not the right tool for this plot. But the answer is very simple: use the basic matplotlib.pyplot.plot function:

import seaborn as sns
import matplotlib.pylab as plt
import pandas
import numpy as np

df = pandas.DataFrame({"a": np.arange(1001, 1001 + 30),
                       "l": ["A"] * 15 + ["B"] * 15,
                       "v": np.random.rand(30)})
g = sns.FacetGrid(row="l", data=df)
g.map(plt.plot, "a", "v", marker="o")
g.set(xticks=df.a[2::8])

这篇关于如何在Seaborn的facetgrid中设置可读的xticks?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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