2017-05-01 57 views
3

私はseabornのfacetgridとデータフレームのこのプロットがありますだけではなく、いくつかを選んで、それは恐ろしい見えるのseabornのfacetgridで読み取り可能なxticksを設定する方法は?

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ラベル:

enter image description here

方法はありますそれらのすべてではなくx軸上のn番目のティックをプロットするようにカスタマイズするには?あなたはこの例のように、手動でのxのラベルをスキップする必要が

+1

:基本matplotlib.pyplot.plot関数を使用します。 – mwaskom

答えて

1

seaborn.pointplotはこのプロットのための右のツールではありません。しかし、答えは非常に簡単です:それは `A`が数値でなければなりませんように見えるとしてあなたはおそらくここに` plt.plot`を使用することにしたい

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]) 

enter image description here

2

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

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

# iterate over axes of FacetGrid 
for ax in g.axes.flat: 
    labels = ax.get_xticklabels() # get x labels 
    for i,l in enumerate(labels): 
     if(i%2 == 0): labels[i] = '' # skip even labels 
    ax.set_xticklabels(labels, rotation=30) # set new labels 
plt.show() 

enter image description here

関連する問題