Search code examples
pythonseabornviolin-plot

How can I change the labels of the x-axis of a seaborn violin plot without going back and changing the data?


I have the following seaborn violin plot:

sns.violinplot( x=c1_census['Cluster Labels'], y=c1_census['Land Area (km2)'],palette=my_pal)
plt.show()

enter image description here

How can I change the labels of the x-axis without going back and changing the data. For example:

Replacing 0 for A, 1 for B, 2 for C, 3 for D, 4 for E

Thanks in advance!


Solution

  • You can use ax.set_xticklabels:

    ax = sns.violinplot( x=c1_census['Cluster Labels'], y=c1_census['Land Area (km2)'],palette=my_pal)
    ax.set_xticklabels([*'ABCDE'])