|
From: Daπid <dav...@gm...> - 2010-08-14 14:47:40
|
Hello. I have had an issue trying to plot an histogram with Matplotlib. The line is: plt.hist([SNIa.angles, SNIbc.angles, SNII.angles], 11, range=[-pi, pi], normed=True,histtype='stepfilled',color=['g', 'r', 'b'],alpha=[1, 0.6, 1]) But the error is raised when I try to save the image. For completness, the whole program is here: http://nopaste.voric.com/paste.php?f=8zl9i4 If I call hist as stated above, I get the following error report: Traceback (most recent call last): File "C:\Documents and Settings\David\Escritorio\Python\IAYC\Supernovae\final\Deprecated\supernovae_bug.py", line 35, in <module> plt.savefig('angular_merged_1bis.png') File "C:\Python25\Lib\site-packages\matplotlib\pyplot.py", line 363, in savefig return fig.savefig(*args, **kwargs) File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line 1084, in savefig self.canvas.print_figure(*args, **kwargs) File "C:\Python25\Lib\site-packages\matplotlib\backend_bases.py", line 1886, in print_figure **kwargs) File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_agg.py", line 438, in print_png FigureCanvasAgg.draw(self) File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_agg.py", line 394, in draw self.figure.draw(self.renderer) File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line 798, in draw func(*args) File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python25\Lib\site-packages\matplotlib\axes.py", line 1934, in draw a.draw(renderer) File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python25\Lib\site-packages\matplotlib\patches.py", line 366, in draw r, g, b, a = colors.colorConverter.to_rgba(self._facecolor, self._alpha) File "C:\Python25\Lib\site-packages\matplotlib\colors.py", line 353, in to_rgba raise ValueError('to_rgba: Invalid rgba arg "%s"\n%s' % (str(arg), exc)) ValueError: to_rgba: Invalid rgba arg "[ 0. 0.5 0. 1. ]" alpha must be in range 0-1 If I delete the color declaring, I get instead: Traceback (most recent call last): File "C:\Documents and Settings\David\Escritorio\Python\IAYC\Supernovae\final\Deprecated\supernovae_bug.py", line 35, in <module> plt.savefig('angular_merged_1bis.png') File "C:\Python25\Lib\site-packages\matplotlib\pyplot.py", line 363, in savefig return fig.savefig(*args, **kwargs) File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line 1084, in savefig self.canvas.print_figure(*args, **kwargs) File "C:\Python25\Lib\site-packages\matplotlib\backend_bases.py", line 1886, in print_figure **kwargs) File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_agg.py", line 438, in print_png FigureCanvasAgg.draw(self) File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_agg.py", line 394, in draw self.figure.draw(self.renderer) File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line 798, in draw func(*args) File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python25\Lib\site-packages\matplotlib\axes.py", line 1934, in draw a.draw(renderer) File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python25\Lib\site-packages\matplotlib\patches.py", line 383, in draw renderer.draw_path(gc, tpath, affine, rgbFace) File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_agg.py", line 117, in draw_path self._renderer.draw_path(gc, path, transform, rgbFace) TypeError: float() argument must be a string or a number And works fine without alpha statement. Any change in the other arguments does not make any difference on the behaviour. If I run it from the IDLE, once I get an error, I continue getting it even if the problematic part is fixed, until I restart the program. I am running Matplotlib 1.0.0 y Python 2.5 sobre WXP. I haven't find any reference to this in the documentation, so it seems to be a bug. Regards, David. |
|
From: Eric F. <ef...@ha...> - 2010-08-14 20:20:03
|
On 08/14/2010 04:47 AM, Daπid wrote: > Hello. > > I have had an issue trying to plot an histogram with Matplotlib. The line is: > > plt.hist([SNIa.angles, SNIbc.angles, SNII.angles], 11, range=[-pi, pi], > normed=True,histtype='stepfilled',color=['g', 'r', > 'b'],alpha=[1, 0.6, 1]) The problem is that the "alpha" kwarg can never be other than a scalar in mpl at present, as far as I know. The error message from to_rgba was intended to be informative, but in this case it is misleading. If you want different alpha values for your different bars, you will have to use a list of rgba values for your color kwarg, and leave out the alpha kwarg. You can construct the list like this (untested): from matplotlib.colors import colorConverter colors = [colorConverter.to_rgba(c, a) for c, a in zip(['g', 'r', 'b'], [1, 0.6, 1]] Eric > > But the error is raised when I try to save the image. For completness, > the whole program is here: > http://nopaste.voric.com/paste.php?f=8zl9i4 > > If I call hist as stated above, I get the following error report: > > Traceback (most recent call last): > File "C:\Documents and > Settings\David\Escritorio\Python\IAYC\Supernovae\final\Deprecated\supernovae_bug.py", > line 35, in<module> > plt.savefig('angular_merged_1bis.png') > File "C:\Python25\Lib\site-packages\matplotlib\pyplot.py", line 363, > in savefig > return fig.savefig(*args, **kwargs) > File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line > 1084, in savefig > self.canvas.print_figure(*args, **kwargs) > File "C:\Python25\Lib\site-packages\matplotlib\backend_bases.py", > line 1886, in print_figure > **kwargs) > File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_agg.py", > line 438, in print_png > FigureCanvasAgg.draw(self) > File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_agg.py", > line 394, in draw > self.figure.draw(self.renderer) > File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 55, > in draw_wrapper > draw(artist, renderer, *args, **kwargs) > File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line 798, in draw > func(*args) > File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 55, > in draw_wrapper > draw(artist, renderer, *args, **kwargs) > File "C:\Python25\Lib\site-packages\matplotlib\axes.py", line 1934, in draw > a.draw(renderer) > File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 55, > in draw_wrapper > draw(artist, renderer, *args, **kwargs) > File "C:\Python25\Lib\site-packages\matplotlib\patches.py", line 366, in draw > r, g, b, a = colors.colorConverter.to_rgba(self._facecolor, self._alpha) > File "C:\Python25\Lib\site-packages\matplotlib\colors.py", line 353, > in to_rgba > raise ValueError('to_rgba: Invalid rgba arg "%s"\n%s' % (str(arg), exc)) > ValueError: to_rgba: Invalid rgba arg "[ 0. 0.5 0. 1. ]" > alpha must be in range 0-1 > > > > If I delete the color declaring, I get instead: > > Traceback (most recent call last): > File "C:\Documents and > Settings\David\Escritorio\Python\IAYC\Supernovae\final\Deprecated\supernovae_bug.py", > line 35, in<module> > plt.savefig('angular_merged_1bis.png') > File "C:\Python25\Lib\site-packages\matplotlib\pyplot.py", line 363, > in savefig > return fig.savefig(*args, **kwargs) > File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line > 1084, in savefig > self.canvas.print_figure(*args, **kwargs) > File "C:\Python25\Lib\site-packages\matplotlib\backend_bases.py", > line 1886, in print_figure > **kwargs) > File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_agg.py", > line 438, in print_png > FigureCanvasAgg.draw(self) > File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_agg.py", > line 394, in draw > self.figure.draw(self.renderer) > File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 55, > in draw_wrapper > draw(artist, renderer, *args, **kwargs) > File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line 798, in draw > func(*args) > File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 55, > in draw_wrapper > draw(artist, renderer, *args, **kwargs) > File "C:\Python25\Lib\site-packages\matplotlib\axes.py", line 1934, in draw > a.draw(renderer) > File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 55, > in draw_wrapper > draw(artist, renderer, *args, **kwargs) > File "C:\Python25\Lib\site-packages\matplotlib\patches.py", line 383, in draw > renderer.draw_path(gc, tpath, affine, rgbFace) > File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_agg.py", > line 117, in draw_path > self._renderer.draw_path(gc, path, transform, rgbFace) > TypeError: float() argument must be a string or a number > > And works fine without alpha statement. Any change in the other > arguments does not make any difference on the behaviour. > > If I run it from the IDLE, once I get an error, I continue getting it > even if the problematic part is fixed, until I restart the program. I > am running Matplotlib 1.0.0 y Python 2.5 sobre WXP. > > I haven't find any reference to this in the documentation, so it seems > to be a bug. > > > > Regards, > > David. > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by > > Make an app they can't live without > Enter the BlackBerry Developer Challenge > http://p.sf.net/sfu/RIM-dev2dev > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
|
From: Friedrich R. <fri...@gm...> - 2010-08-18 20:36:28
|
2010/8/14 Eric Firing <ef...@ha...>: > colors = [colorConverter.to_rgba(c, a) for c, a in zip(['g', 'r', 'b'], If it is this (I didn't dig into the program) it will be fixed soon I hope :-) Friedrich |
|
From: Daπid <dav...@gm...> - 2010-08-22 14:51:36
|
On Sat, Aug 14, 2010 at 10:19 PM, Eric Firing <ef...@ha...> wrote: > The problem is that the "alpha" kwarg can never be other than a scalar > in mpl at present, as far as I know. The error message from to_rgba was > intended to be informative, but in this case it is misleading. Thanks for your response. I was following the logic for colors, which does accept lists. Anyway, the error message is diferent if I set the color or not, which is not logical. By the way, do you have any clue on the persistence of the problem until the IDLE is restarted? I mean, even with the code fixed, the error is still raised until IDLE is reopened. Thank you again, David. |
|
From: Eric F. <ef...@ha...> - 2010-08-22 22:54:08
|
On 08/22/2010 04:51 AM, Daπid wrote: > On Sat, Aug 14, 2010 at 10:19 PM, Eric Firing<ef...@ha...> wrote: >> The problem is that the "alpha" kwarg can never be other than a scalar >> in mpl at present, as far as I know. The error message from to_rgba was >> intended to be informative, but in this case it is misleading. > > Thanks for your response. I was following the logic for colors, which > does accept lists. That was a reasonable thing to do, but unfortunately, for historical reasons, there are inconsistencies and ambiguities associates with the alpha kwarg in mpl. > > Anyway, the error message is diferent if I set the color or not, which > is not logical. Granted. This is one of many situations in which the error message is not very informative. We don't have a consistent policy for validating kwargs, so invalid values can filter down into the depths of the code before they trigger an exception. > > By the way, do you have any clue on the persistence of the problem > until the IDLE is restarted? I mean, even with the code fixed, the > error is still raised until IDLE is reopened. > If you are fixing code that is in a module that has been imported, IDLE may be using the old code, not the new. This is inherent in python--importing a module that has already been imported does not rerun the code in that module, or change any existing objects. There are ways of getting around this, at least with respect to function and class definitions, but usually it is easier, surer, and cleaner to restart the python interpreter so that everything is clearly using the new code. Eric > > Thank you again, > > David. |