incorrect Colorbar for log values in scatter plot

2019-05-23 23:01发布

I want to use a scatter plot to describe the relationship between X, Y and Z. Z is p-value so it is better to denote it as log values.

Following the instructions here, I can plot a logarithmic scatter plot, but the color bar seems wrong. The color bar is almost totally blue, but there should be some red! Below is the figure and my codes. enter image description here

import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.colors import LogNorm

fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ax1.set_title("P-value")

Z1 = pos_spearmanr['pval']
X = pos_spearmanr['X']
Y = pos_spearmanr['Y']

im = ax1.scatter(X,
                 Y, 
                edgecolors=None,
                c=Z1,
                norm=LogNorm(),
                cmap=plt.get_cmap('bwr'), alpha=0.2)

ax1.set_xlabel('X')
ax1.set_ylabel('Y')
ax1.set_xlim(0, 1)
ax1.set_ylim(0, 1)
cbar = fig.colorbar(im,ax=ax1)

0条回答
登录 后发表回答