Seaborn/Matplotlib - Only Showing Certain X Values in FacetGrid
<p>I am trying to create a facet of charts that show total scores over time, in seconds.  X axis is the time in seconds and y axis is the total score.</p>

<p>As you can see, I am restricting the output to 2 1/2 minutes via xlim .  </p>

<p>What I would like to do is to only show values on the xaxis for every 30 seconds (i.e. 30, 60, 90, 120, 150).. I still want to show the values of (for example) 10 and 15 seconds on the chart, just not on the labels on the xaxis.</p>

<p>How do I modify the code below to do this?  Been trying various forms of xticks and xlabel but just can't figure it out.. Google has not been my friend either..</p>

<p>Would really appreciate some help</p>

<p>Thanks</p>

<pre><code>df = pd.DataFrame({'Subject': ['Math', 'Math', 'Math','Math', 'Math', 'Math', 'Math','Math', 'Math', 'Math','English', 'English', 'English','English', 'English', 'English', 'English','English', 'English', 'English'], 
               'timeinseconds': [1, 10, 15, 30, 45, 60, 90, 120, 140, 150,1, 10, 15, 30, 45, 60, 90, 120, 140, 150], 
               'totalscore': [.2, .3, .4, .37, .45, .55, .60, .54, .63, .72,
               .4, .34, .23, .52, .56, .59, .63, .66, .76, .82]})

g = sns.FacetGrid(df, col="Subject", col_wrap=5, size=3.5, ylim=(0, 1),xlim=(0,360))
g = g.map(sns.pointplot, "timeinseconds", "totalscore", scale=.7)
</code></pre>

<p>This will solve your problem:</p>

<pre><code>g = (g.map(sns.pointplot, "timeinseconds", "totalscore", scale=.7)
    .set(xticks=[3, 5, 6, 7, 9], xticklabels=[30, 60, 90, 120, 150]))
</code></pre>

<p>The <code>xticks</code> indicate the positions where you want to place the labels  (numbered from <code>0</code> to <code>n-1</code> where <code>n</code> is the original number of ticks), and <code>xticklabels</code> the actual labels. </p>

<p>You can certainly find a way to do it with less hard-coding.</p>

python pandas matplotlib seaborn facet