python - Matplotlib ColorbarBase : delete color separators

标签 python matplotlib colorbar

我想使用 ColorbarBase 删除绘制的颜色图中的背线分隔符(分隔线?):

cm    = get_cmap('RdBu')
Ncol  = 501
cccol = cm(1.*arange(Ncol)/Ncol)
cax     = fig.add_axes([0.15,0.15,0.05,0.4])
fig.add_axes([0.5,0.15,0.3,0.03])
norm    = mpl.colors.Normalize(vmin=valmin, vmax=valmax)
cb1     = mpl.colorbar.ColorbarBase(cax, cmap=cm, norm=norm, orientation='vertical')

中间总是给我太多黑线..有没有办法消除它们?我已经尝试过类似的东西:

del cb1.lines
del cb1.dividers

cb1.lines.remove()
cb1.lines = []

http://fossies.org/dox/matplotlib-1.2.0/matplotlib_2colorbar_8py_source.html#l00281 中的 ColorbarBase 方法所示.

colorbar with too many black lines

最佳答案

这对我有用,没有任何台词。我看到两种明显的可能性:

1) 你有一个错误的版本。如果我在 python 提示符下执行 matplotlib.__version__,我会看到 1.2.0。我正在使用 OS X 10.6.8 和 python 2.7.3,以及从 macports 安装的所有内容。你呢?

2) 这是您没有向我们展示的代码中的某些内容。对于这样的问题,您应该始终展示一个最小的工作示例。 (这有时可以帮助您在提出问题之前弄清楚问题。)例如,我可以启动 ipython --pylab,然后执行以下操作:

fig    = figure()
valmin =-1.0
valmax =1.0
cm     = get_cmap('RdBu')
Ncol   = 501
cccol  = cm(1.*arange(Ncol)/Ncol)
cax    = fig.add_axes([0.15,0.15,0.05,0.4])
norm   = mpl.colors.Normalize(vmin=valmin, vmax=valmax)
cb1    = mpl.colorbar.ColorbarBase(cax, cmap=cm, norm=norm, orientation='vertical')
draw()
savefig('/tmp/bla.png')

弹出的 GUI 和保存的 PNG 均显示以下内容:

Colorbar

这对你有用吗?您是否在其余代码中做了一些明显不同的事情?

关于python - Matplotlib ColorbarBase : delete color separators,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16172869/

相关文章:

python - 使用 matplotlib 绘制 netCDF 数据的奇怪图

python - 绘制方程显示一个圆

Python matplotlib - 如何在不调整热图大小的情况下移动颜色条?

python - 使用 seaborn 绘制时间序列数据

python - Perl 中有类似 Python Itertools 的东西吗?

python - 如何读取和搜索多个文本文件,以便存储与我的搜索匹配的文件列表?

python - 正则表达式验证版权

python - 颜色条设置刻度格式器/定位器更改刻度标签

python - 滚动 Matplotlib 颜色条

python - 使用 Google Apps 脚本 API 可执行文件的服务器到服务器身份验证