|
From: Nils W. <ni...@go...> - 2013-10-11 08:34:31
|
plt.colorbar(scalarMap,ax=ax) results in
cm.py", line 309, in autoscale_None
raise TypeError('You must first set_array for mappable')
TypeError: You must first set_array for mappable
Nils
On Fri, Oct 11, 2013 at 9:51 AM, Eric Firing <ef...@ha...> wrote:
> 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
> > Mat...@li...
> > 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
|