简体   繁体   中英

Setting the interval of x-axis for seaborn plot

I have a set of subplots to plot. Here, how do we set the interval for x-axis in the subplot in second row, ie ax4 to ax6 . Currently all the values from 1 to 100 are printed as shown in the figure. I tried ax4.set_xticks(range(1,100,5)) . But there, the range shown was 1 to 20. I was expecting a range from 1 to 100, with an interval of 5, ie 1,5,10...95,100

Currently the plot has x-axis as shown below. I have not added the code for first row.

在此输入图像描述

yInit = initRes
yInit = yInit[(yInit['nodeSKT'] < 92) & (yInit['nodeSKT'] > 1)]

sns.set_context("paper", font_scale=2, rc={"lines.linewidth": 1.2})
fig, (ax4, ax5, ax6) = plt.subplots(nrows=1,ncols=3,figsize=(18,10))
plt.figure()

xval = 'nodeSKT'
sns.pointplot(x=xval, y='lemmaPrec', data=yInit,join=False,ax=ax4)
sns.pointplot(x=xval, y='wordPrec',color="#2ecc71",data=yInit, join=False,ax=ax4)
sns.pointplot(x=xval, y='lemmaReca', data=yInit,join=False,ax=ax5)
sns.pointplot(x=xval, y='wordReca',color="#2ecc71",data=yInit, join=False,ax=ax5)
sns.pointplot(x=xval, y='lemmaFsco', data=yInit,join=True,ax=ax6)
sns.pointplot(x=xval, y='wordFsco',color="#2ecc71",data=yInit, join=False,ax=ax6)
plt.savefig('lem_fscore.png')

Seaborn pointplot is a categorical plot. This means that the different categories are simply placed one by one along the x axis.

The idea would therefore be to change the locator as well as the formatter for the xticks.

import seaborn.apionly as sns
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import numpy as np; np.random.seed(1)

x = np.random.randint(0,20,size=(100))
y = np.random.rand(100)

ax = sns.pointplot(x,y )
ax.xaxis.set_major_locator(ticker.MultipleLocator(5))
ax.xaxis.set_major_formatter(ticker.ScalarFormatter())

plt.show()

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM