On 2014/11/03, 2:19 PM, Damien Irving wrote:
> I often like to define my own colormaps using hex strings, e.g.
> hex_list = ['#FFF295', '#FFD555', '#FF850B', '#D55000', '#D50000',
> '#550040','#600080', '#000080', '#0000D5', '#0B85FF', '#55AAFF', '#95CAFF']
>
> However, when I pass them to contourf and try to extend the colorbar...
> plt.contourf(x, y, data, colors=hex_list, extend='both')
>
> ... it always ends up that the color of the final segment on the
> extended ends of the colorbar is the same color as the extension segment
> (i.e. the bit in the little arrow). This happens even when hex_list is
> much longer than the actual number of segments required.

You need to use the "levels" kwarg to specify the contour interval 
boundaries, and then your list of colors needs to have a length equal to 
len(levels) + 1.  In other words, the number of colors listed in the 
colors kwarg needs to be *exactly* the number needed to fill between the 
  specified levels, plus one for each requested "extend" direction, if any.

plt.contourf(x, y, data, levels=[0, 1, 2],
              colors=['red', 'blue, 'brown', 'black'],
              extend='both')

That should give you blue and brown for 0-1 and 1-2; with red for 
data<0, and black for data>2.

Eric

>
> Has anyone else had this problem?
>
>
>
> ------------------------------------------------------------------------------
>
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>


------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to