Reputation: 1132
After creating a Pandas dataframe, I am generating a Seaborn heatmap using the following commands:
# Create heatmap
f, ax = plt.subplots(figsize=(20, 10))
g = sns.heatmap(df_abs, cmap='inferno', vmin=0.0, vmax=1.0, xticklabels='auto')
loc, labels = plt.xticks()
g.set_xticklabels(labels, rotation=0)
loc, labels = plt.yticks()
g.set_yticklabels(labels, rotation=0)
sns.set(font_scale=4)
plt.title('Spectral absorption')
plt.xlabel('Frequency [THz]')
plt.ylabel('Angle of Incidence [$^o$]')
plt.show()
However, my x-axis is still ugly:
-- how can I specify the start value, end value, increment value, and make the values into integers? I've tried looking through the documentation for both plt.xlabel
, g.set_xticklabels
, and sns.heatmap
options, but I'm having trouble finding a solution.
Upvotes: 0
Views: 2745
Reputation: 339200
From the seaborn.heatmap
documentation:
xticklabels
,yticklabels
: “auto”, bool, list-like, or int, optionalIf True, plot the column names of the dataframe. If False, don’t plot the column names. If list-like, plot these alternate labels as the xticklabels. If an integer, use the column names but plot only every n label. If “auto”, try to densely plot non-overlapping labels.
Hence
sns.heatmap(..., xticklabels=5)
will give you 5 ticklabels. Or
sns.heatmap(..., xticklabels=["1","Banana","12/12/2018"])
will label the categories as "1","Banana","12/12/2018"
.
If this is not what you're after, probably you wouldn't even want a seaborn heatmap at all. But rather a usual pcolormesh
plot, which uses a numeric axis, instead of a categorical one and hence allows to set the ticks and ticklabels to your liking.
Upvotes: 1