How to reformat tick labels of one axis to scientific notation in seaboard.heatmap?

Viewed 22

I have a seaborn heat map:

enter image description here produced by the following code:

pivot_table = data_frame.pivot(index=['df_col1'], columns='df_col2', values='df_col3')
    
sns.heatmap(data=pivot_table, cmap='rainbow')
plt.xlabel('mpdist')
plt.ylabel('max [particles]')
plt.show()

Now, I would like to have the y-axis tick labels in scientific notation. I already looked around in the web, but didn't succeed. There was a formatter approach in some other stack overflow thread:

import matplotlib.ticker as tkr

formatter = tkr.ScalarFormatter(useMathText=True)
formatter.set_scientific(True)
formatter.set_powerlimits((0,0))    

ylabels = [u"${}$".format(formatter.format_data(x)) for x in roc_pivot.index.values]

sns.heatmap(data=roc_pivot, cmap='rainbow', , yticklabels=ylabels)
...

but this gives me a math domain error. As well the approach

plt.ticklabel_format(style='sci', axis='y')

causes an error: This method only works with the ScalarFormatter

0 Answers
Related