Python 蜘蛛图:减少 y 轴

Python Spiderplot: reduce y-axis

我正在寻找将 y 轴的间隔减少到 0、20、40、60、80 和 100 的方法

我的图表目前看起来像这样:

这是我正在使用的代码:

import pandas as pd
import seaborn as sns
from matplotlib.ticker import MaxNLocator

df = pd.DataFrame({'Day': ['1.Monday', '2.Tuesday', '3.Wednesday', '4.Thursday', '5.Friday'],
                  'Percentage': [71, 35, 27, 63, 91]})


ax = sp.spiderplot(x="Day", y='Percentage',  legend= False,
               data=df, palette="husl", rref=0)
ax.set_rlim([0,100])
ax.yaxis.set_major_locator(MaxNLocator(integer=True))   

# plt.title(state, fontsize=20)
plt.xticks(rotation=0)
ax.tick_params(axis='y', labelsize=15)
ax.tick_params(axis='x', labelsize=20)
plt.show()

我以前没有用过这个库,但是你可以添加下面的代码来支持它。

import pandas as pd
import numpy as np
import seaborn as sns
import spiderplot as sp
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator

df = pd.DataFrame({'Day': ['1.Monday', '2.Tuesday', '3.Wednesday', '4.Thursday', '5.Friday'],
                  'Percentage': [71, 35, 27, 63, 91]})


ax = sp.spiderplot(x="Day", y='Percentage',  legend= False,
               data=df, palette="husl", rref=0)
ax.set_rlim([0,100])
ax.yaxis.set_major_locator(MaxNLocator(integer=True))   

# plt.title(state, fontsize=20)
plt.xticks(rotation=0)
ax.set_yticks(np.arange(0,100,20)) #update
ax.tick_params(axis='y', labelsize=15)
ax.tick_params(axis='x', labelsize=20)
plt.show()