Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjusting tick settings on Seaborn heatmap

I've been trying to adjust the tick settings for a heat map through several different methods with no success. The only method that actually changes the settings of the plot is plt.xticks(np.arange(217, 8850, 85)) but even when using several different intervals for this method the data is skewed greatly to the right.

When the tick labels aren't clumped together (for example using plt.xticks(np.arange(217, 8850, 500))) the last tick mark on the end of the axis is no where near the 8850 max I need to show all the data.

I'm trying to adjust these tick settings on both the x and y in order to view the full range of data (Xmax: 8848 Xmin: 7200, Ymax: 8848 Ymin:217) with intervals that allow the tick labels to be readable.

Images of Heatmap:

First image is with plt.xticks(np.arange(217, 8850, 500)):

enter image description here

Second image is with plt.xticks(np.arange(217, 8850, 85)):

enter image description here

Third is original Heatmap:

enter image description here

 color = 'seismic'
 success_rate = (m['Ascents'] / ((m['Ascents']) + (m['Failed_Attempts'])))*100
 success_rate.fillna(0).astype(float)
 mm['success_rate'] = success_rate
 mm['success_rate'].round(2)
 vm = mm.pivot("Height(m)", "Prominence(m)", "success_rate")
 cPreference = sns.heatmap(vm, vmax = 100, cmap = color, cbar_kws= {'label': 'Success Rate of Climbs (%)'})
 cPreference = cPreference.invert_yaxis()


 """Methods I've Tried"""
 plt.xticks(np.arange(217, 8850, 1000)) """<< Only line that actually makes visible changes but data is skewed greatly"""

 cPreference.xaxis.set_ticks(np.arange(mm["Height(m)"].min(), mm["Height(m)"].max(), (mm["Height(m)"].max() - \
 mm["Height(m)"].min()) / 10))
 cPreference.yaxis.set_ticks(np.arange(mm["Prominence(m)"].min(), mm["Prominence(m)"].max(), (mm["Prominence(m)"].max() \
 - mm["Prominence(m)"].min()) / 10))

 sns.set_style("ticks", {"xtick.major.size" : 8, "ytick.major.size" : 8})

 plt.title("What is a good Mountain to Climb?")
 sns.plt.show()
like image 802
Jacob Snow Avatar asked Jul 13 '17 13:07

Jacob Snow


People also ask

How do I reduce the number of ticks in Seaborn?

To decrease the density of x-ticks in Seaborn, we can use set_visible=False for odd positions.

How do you increase the size of annotation text in heatmap?

The annotations follow a default font size but it can be changed using the annot_kws parameter of heatmap() function, annot_kws is a dictionary type parameter that accepts value for the key named size.


1 Answers

cPreference = sns.heatmap(vm, vmax = 100, cmap = color, >>> xticklabels = 10, yticklabels = 5 <<<, cbar_kws={'label': 'Success Rate of Climbs (%)'})

By setting xticklabels or yticklabels equal to an integer it will still plot the same column but it will only display every nth item in that column.

like image 58
Jacob Snow Avatar answered Sep 19 '22 06:09

Jacob Snow