Seaborn/Matplotlib - Only Showing Certain X Values in FacetGrid

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.

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

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.

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..

Would really appreciate some help

Thanks

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)

Upvotes: 2

Views: 3181

Answers (1)

IanS
IanS

Reputation: 16251

This will solve your problem:

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

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

You can certainly find a way to do it with less hard-coding.

Upvotes: 1

Related Questions