创建matplotlib colored颜色 栏时,可以将drawedges设置为True,将 colored颜色 栏的 colored颜色 与黑线隔开.然而,当使用extend='both'扩展 colored颜色 条时,末端的黑线不会显示.那是虫子吗?是否有可能以其他方式绘制这些边?

以下是代码:

import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt  
from matplotlib.colors import from_levels_and_colors

my_cmap = mpl.cm.viridis
bounds = np.arange(10)
nb_colors = len(bounds) + 1
colors = my_cmap(np.linspace(100, 255, nb_colors).astype(int))
my_cmap, my_norm = from_levels_and_colors(bounds, colors, extend='both')

plt.figure(figsize=(5, 1))
ax = plt.subplot(111)
cbar = mpl.colorbar.ColorbarBase(ax, cmap=my_cmap, norm=my_norm, orientation='horizontal', drawedges=True)
plt.subplots_adjust(left=0.05, bottom=0.4, right=0.95, top=0.9)
plt.show()

它给出的数字是:

enter image description here

推荐答案

我根据你的问题进行了研究,找到了一种改变边框 colored颜色 和 colored颜色 栏垂直线的方法.我用它把它们变成了红色.我得到的结果是,扩展的轮廓是红色的,所以我猜我只是将正常 colored颜色 栏矩形的短边向左和向右拉.

cbar.outline.set_edgecolor('red')
cbar.dividers.set_color('red')

enter image description here

我认为只有垂直的方式才能添加线条.

import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt  
from matplotlib.colors import from_levels_and_colors

my_cmap = mpl.cm.viridis
bounds = np.arange(10)
nb_colors = len(bounds) + 1
colors = my_cmap(np.linspace(100, 255, nb_colors).astype(int))
my_cmap, my_norm = from_levels_and_colors(bounds, colors, extend='both')

plt.figure(figsize=(6, 2))
ax = plt.subplot(111)
cbar = mpl.colorbar.ColorbarBase(ax, cmap=my_cmap, norm=my_norm, orientation='horizontal', drawedges=True)
# update
cbar.outline.set_edgecolor('red')
cbar.dividers.set_color('red')
plt.axvline(max(bounds), color='red', alpha=0.3, linewidth=3.5)
plt.axvline(min(bounds), color='red', alpha=0.3, linewidth=3.5)

plt.subplots_adjust(left=0.05, bottom=0.4, right=0.95, top=0.9)
plt.show()

enter image description here

Python相关问答推荐

使用itertools出现第n个子串

来自ARIMA结果的模型方程

带有pandas的分区列上的过滤器的多个条件read_parquet

如何判断LazyFrame是否为空?

使用Python Great Expectations和python-oracledb

为什么基于条件的过滤会导致pandas中的空数据框架?

将DF中的名称与另一DF拆分并匹配并返回匹配的公司

由于NEP 50,向uint 8添加-256的代码是否会在numpy 2中失败?

仿制药的类型铸造

Deliveryter Notebook -无法在for循环中更新matplotlib情节(保留之前的情节),也无法使用动画子功能对情节进行动画

Mistral模型为不同的输入文本生成相同的嵌入

如何在solve()之后获得症状上的等式的值

Stacked bar chart from billrame

在极性中创建条件累积和

为什么NumPy的向量化计算在将向量存储为类属性时较慢?'

将JSON对象转换为Dataframe

用砂箱开发Web统计分析

用渐近模计算含符号的矩阵乘法

启动带有参数的Python NTFS会导致文件路径混乱

matplotlib + python foor loop