【发布时间】:2020-06-06 06:09:34
【问题描述】:
df.columns = ['feature','nunique']
sns.set(rc={'figure.figsize':(10,8)})
ax = sns.barplot(y='feature', x='nunique', data=df, orient = 'h')
如何将 nunique(x 轴)划分为更小的网格?
【问题讨论】:
标签: python matplotlib plot seaborn
df.columns = ['feature','nunique']
sns.set(rc={'figure.figsize':(10,8)})
ax = sns.barplot(y='feature', x='nunique', data=df, orient = 'h')
如何将 nunique(x 轴)划分为更小的网格?
【问题讨论】:
标签: python matplotlib plot seaborn
您可以使用 matplotlib 中的ticker,所以从vignette 可以:
类 matplotlib.ticker.MultipleLocator(base=1.0)
在视图中基数的每个整数倍上设置一个刻度 间隔。
我们需要将绘图分配给轴类并像这样修改它:
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib.ticker as ticker
import numpy as np
sns.set()
tips = sns.load_dataset("tips")
fig, ax = plt.subplots(1, 2,figsize=(10,4))
sns.barplot(x="total_bill",y="day",data=tips,ax=ax[0],ci=None)
ax[0].xaxis.set_major_locator(ticker.MultipleLocator(2.5))
sns.barplot(x="total_bill",y="day",data=tips,ax=ax[1],ci=None)
ax[1].xaxis.set_major_locator(ticker.MultipleLocator(1))
【讨论】:
将 your_ticks 更改为一个数组,其中包含您希望在 x 轴上显示的数字。
fig, ax = plt.subplots()
sns.barplot(y='feature', x='nunique', data=df, orient = 'h')
ax.set_xticks(your_ticks)
【讨论】: