Agnes Lee
Agnes Lee

Reputation: 321

Python Spiderplot: reduce y-axis

I am looking for ways to reduce the intervals of y-axis to 0, 20, 40, 60, 80, & 100

My graph currently looks like this:

enter image description here

This is the code I'm using:

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()

Upvotes: 0

Views: 60

Answers (1)

r-beginners
r-beginners

Reputation: 35205

I have not used this library before, but you can add the following code to support it.

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()

enter image description here

Upvotes: 1

Related Questions