0

Three things I hope to edit on this correlation graph.

  1. Remove the white space on top. I tried plt.tight_layout(pad=0) and plt.gcf().subplots_adjust(wspace=0, hspace=0). But both methods failed.
  2. I tried to add ticks by sns.set_style({'xtick.bottom': True}, {'ytick.left': True}) but strangely it didn't work as shown in screenshot of the graph.
  3. How to limit the correlation coefficients to just two digits?

Below is the whole codes I used.

sns.set(style="white")
corr = by_profit.T.corr()
mask = np.triu(np.ones_like(corr, dtype=np.bool))
f, ax = plt.subplots(figsize=(10, 9),dpi=100)
sns.heatmap(corr, mask=mask, cmap='coolwarm', vmax=1, vmin=-1,center=0,
            square=True, linewidths=.5, cbar_kws={"shrink": .5},annot = True,
                      annot_kws = {"size": 9})
ax.set_xticklabels(c.get_xticklabels(), rotation=45, horizontalalignment='right')
sns.set_style({'xtick.bottom': True}, {'ytick.left': True})
plt.title('Correlation Between Sub-Category Sales')
plt.xlabel('')
plt.ylabel('');

enter image description here

flyunicorn
  • 31
  • 3
  • Please limit your post to one question. As it stands, I'm sure all your questions are dupes, but I don't know which to link to. – Diziet Asahi Aug 30 '20 at 20:15
  • For instance, about the annotation format, refer to this question https://stackoverflow.com/questions/54506626/how-to-understand-seaborns-heatmap-annotation-format/54506793 – Diziet Asahi Aug 30 '20 at 20:17
  • Answer about the space around the plot https://stackoverflow.com/questions/4042192/reduce-left-and-right-margins-in-matplotlib-plot – Diziet Asahi Aug 30 '20 at 20:25
  • @DizietAsahi Actually I found the post about space you linked before posting this question. But I didn't need to save the image to file, only showing on jupyter notebook. So I tried `plt.tight_layout(pad=0)` and `plt.gcf().subplots_adjust(wspace=0, hspace=0)`, which were mentioned at the end of the link, but neither works. – flyunicorn Aug 31 '20 at 02:11
  • Can someone pls help? I can separate this post into three questions if that's necessary. Thanks! – flyunicorn Sep 03 '20 at 04:04

0 Answers0