python - 提高 matplotlib 中的颜色对比度
问题描述
我有一个超过 13000 个像素的散点图,这些像素根据标签分为 50 个集群。在这种情况下,标签代表对应于像素的化学实体(见图)。我通过将标签转换为数字 [0,50] 然后将这些数字更改为 rgb 值,根据标签为像素着色。虽然这可行,但相邻标签之间的对比度不够好。例如,在图中,前四个标签都是蓝色的,而后七个标签是棕色的。这无助于我区分标签。有没有办法可以改善相邻标签之间的颜色对比度?
class_colors=np.arange(0,50) # each integer corresponds to a label
class_colors_float=[]
for i in class_colors:
class_colors_float.append(round(i/len(class_colors),2))
cmap=plt.cm.get_cmap('Paired') # choosing a color map
rgba=cmap(class_colors_float) # converting the color map to rgb values
# creating scatter plot
t=ax.scatter(...,cmap=plt.cm.get_cmap('Paired'))
recs = [] # creating rectange patches for the legends
# coloring each rectangle according to the label it corresponds to
for i in range(0,len(class_colors)):
recs.append(mpatches.Rectangle((0,0),1,1,facecolor=rgba[i]))
plt.legend(recs,classes,loc='best',bbox_to_anchor=(1,0,1,1),mode='expand')
解决方案
推荐阅读
- php - 同一个 WooCommerce 钩子必须始终使用相同的参数集吗?
- python - Pygame:一种在显示大量对象之前快速查找屏幕内容的方法
- java - 比较java中的日期。搜索今天,明天
- anaconda - anaconda 中的 Spyder 比 x2go 慢
- android - 我的自定义数组列表在 android Kotlin 中没有正确排序
- php - PHP Laravel GraphQL 查询声明不兼容问题
- c++ - 使用 extern const 用函数初始化 const
- gnuplot - 一张图四张图
- postgresql - 在参数周围转义单引号时出错
- java - 线程是代码本身还是某个实体?