I want to change values on X and Y-axis in seaborn scatter plot to words. Below is my code to draw a scatter plot with values. Before that I replaced all user input (words) in pandas Data Frame to float type, cause It doesn't draw plot with letters, but now I need to change X and Y-axis values to words.
sns.pairplot(data=db, y_vars=['Dayanswer'], x_vars=['Season','Day'])
Here is the scatter plot with values on X and Y-axis I want to change on Y-axis: '1.0' to Good, '0.5' to 'Normal' and '0.0' to 'Bad', and on X-axis: in season '2.0' to 'Spring', '3.0' to 'Summer', in Day: '1' to 'Monday', '2' to 'Tuesday' and so on to get something like this . How can I do it?
Use set_xticks
, set_xticklabels
and so on from matplotlib library to achieve your purpose:
import seaborn as sns
import matplotlib.pylab as plt
iris = sns.load_dataset("iris")
pp = sns.pairplot(data=iris, x_vars=['sepal_length', 'sepal_width'], y_vars=['petal_width'])
# set y labels
for ax in pp.axes.flat: # iterate over all axes object of pairplot
ax.set_yticks([1.,.5,.0])
ax.set_yticklabels(['Good','Normal','Bad'])
# set x labels
# 1st plot
pp.axes[0,0].set_xticks([0,1,2,3])
pp.axes[0,0].set_xticklabels(['Winter','Spring','Summer','Autumn'])
# 2nd plot
pp.axes[0,1].set_xticks([0,1,2,3,4,5,6,7])
pp.axes[0,1].set_xticklabels(['Mon','Tue','Wen','Thu','Fri','Sut','Sun'])
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With