incorrect Colorbar for log values in scatter plot

两盒软妹~` 提交于 2020-01-13 19:43:25

问题


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.

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)

来源:https://stackoverflow.com/questions/35004088/incorrect-colorbar-for-log-values-in-scatter-plot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!