Re: [Matplotlib-users] AttributeError: 'BarContainer' object has no attribute 'autoscale_None'
Nils, Here is a version that runs through. It produces two different versions of your graph: one with the colors corresponding to the index of the arrays, the other with the colors corresponding to the value of the histogram. I hope this helps. -Sterling {{{ import re import os import sys import gzip import numpy as np import matplotlib.pyplot as plt import glob from mpl_toolkits.mplot3d import Axes3D import matplotlib.colors as colors import matplotlib.cm as cmx efratio = np.loadtxt('efratio-10.dat.gz') 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 coolwarm = cm = plt.get_cmap('coolwarm') values = range(100) for normed in [values,hist]: cNorm = colors.Normalize(vmin=0, vmax=max(normed)) scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=coolwarm) colours = [] for value in normed: colorVal = scalarMap.to_rgba(value) colours.append(colorVal) fig = plt.figure() ax = fig.add_subplot(111,projection='3d') heatmap = ax.bar(center, hist, zs=1, zdir='y', align = 'center', width = width,color=colours,linewidth=0) scalarMap.set_array(normed) plt.colorbar(scalarMap,ax=ax) plt.show() }}} On Oct 14, 2013, at 6:12AM, Nils Wagner wrote: Here is a self contained version. Nils On Fri, Oct 11, 2013 at 4:33 PM, Sterling Smith smit...@fusion.gat.com wrote: Nils, I tried to run your example, but there are some variables which are undefined. Can you post a self contained revision of your example? -Sterling On Oct 11, 2013, at 1:34AM, Nils Wagner wrote: 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 efir...@hawaii.edu 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=60134071iu=/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=60134071iu=/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=60134071iu=/4140/ostg.clktrk___
[Matplotlib-users] AttributeError: 'BarContainer' object has no attribute 'autoscale_None'
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' How can I fix the problem ? 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=60134071iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] AttributeError: 'BarContainer' object has no attribute 'autoscale_None'
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=60134071iu=/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=60134071iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] AttributeError: 'BarContainer' object has no attribute 'autoscale_None'
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 efir...@hawaii.edu 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=60134071iu=/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=60134071iu=/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=60134071iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] AttributeError: 'BarContainer' object has no attribute 'autoscale_None'
Nils, I tried to run your example, but there are some variables which are undefined. Can you post a self contained revision of your example? -Sterling On Oct 11, 2013, at 1:34AM, Nils Wagner wrote: 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 efir...@hawaii.edu 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=60134071iu=/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=60134071iu=/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=60134071iu=/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=60134071iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users