On 2013/10/10 8:52 PM, Nils Wagner wrote:
> Hi all,
>
> I tried to add a colorbar to a bar plot
>
> coolwarm = cm =  plt.get_cmap('coolwarm')
> values = range(100)
> cNorm  = colors.Normalize(vmin=0, vmax=values[-1])
> scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=coolwarm)
> colours = []
> for value in values:
>      colorVal = scalarMap.to_rgba(value)
>      colours.append(colorVal)
>
> fig = plt.figure()
> ax  = fig.add_subplot(111,projection='3d')
> hist,bin_edges = np.histogram(efratio,bins=100,range=(0.,1.),density=False)
> width = 0.7*(bin_edges[1]-bin_edges[0])
> center = (bin_edges[:-1]+bin_edges[1:])/2
> heatmap = ax.bar(center, hist, zs=z, zdir='y', align = 'center', width =
> width,color=colours)
> plt.colorbar(heatmap)
>
>
>
>
>
>      mappable.autoscale_None() # Ensure mappable.norm.vmin, vmax
> AttributeError: 'BarContainer' object has no attribute 'autoscale_None'

This is because it is not an instance of ScalarMappable, which is what 
colorbar() requires as its argument.
>
> How can I fix the problem ?

Use scalarMap as the argument instead of heatmap.  I think you will need 
to provide either the cax or the ax kwarg in addition.

examples/api/colorbar_only.py might also be helpful.

Eric
>
> Nils
>
>
>
> ------------------------------------------------------------------------------
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
>
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to