[Matplotlib-users] 2D array plot picking explicit values to colour and legend

2012-04-09 Thread Mathew Topper
Dear matplotlib-users,

I have a spatial data set that has coded values for each cell, which are 
limited to just a few numbers, ie -, 0, 100, and . I would like 
to display this data with a plot similar to pcolor, but I don't want a 
colorbar, I want a legend showing the colors for each code and an 
explanation for what each code represents. I would like to be able to 
choose a subset of the codes as well, for example just plotting the 0 
and 100 codes and ignoring the - and  codes.

I have seen a few similar attempts that used BoundaryNorm, but I don't 
want to show a range of values I just want to set colors for a few 
explicit values. Those examples also had a colorbar and, as I said, I 
would prefer a legend.

Can anyone offer any tips?

Thanks

Mat

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.


--
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] corrupt pdf of histogram

2012-04-09 Thread Jouni K . Seppänen
Benjamin Root  writes:

>> sanders  writes:
>>
>> > If keywords fill=False and log=True,
>> >
>> > then after saving, the png looks fine but the histogram in the pdf is
>> > mixed up.
>>
>> Confirmed, thanks for the report. I filed this at
>> https://github.com/matplotlib/matplotlib/issues/804
>
> I ran into something like this with filled plots originally saved as eps
> files and then converted into a pdf.  Didn't need log=True, though.  

I think that's likely a different issue. The eps output machinery in
matplotlib is somewhat complicated, which it likely has to be to
function well with various eps-handling software, and incorporate
LaTeX-rendered equations. With all the various steps (including
distilling through an external program) it's difficult to debug what
goes wrong.

In the original problem, it seems that the path-cropping functionality
used in logarithmic plots is outputting paths that work in Agg but not
in pdf or svg. It basically rewrites

  moveto X0,Y0 (outside plottable area)
  lineto X1,Y0 (outside plottable area)
  lineto X1,Y1 (inside)
  lineto X0,Y1 (inside)
  closepath

into

  moveto X0,Y0' (Y0' is Y0 rewritten to be close to the area)
  moveto X1,Y0'
  lineto X1,Y1
  lineto X0,Y1
  closepath

and the closepath operation apparently goes to the first moveto in Agg,
but to the latest moveto in pdf and svg.

I have a suggested fix for this at
https://github.com/matplotlib/matplotlib/pull/817 

-- 
Jouni K. Seppänen
http://www.iki.fi/jks


--
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] 2D array plot picking explicit values to colour and legend

2012-04-09 Thread Eric Firing
On 04/09/2012 02:22 AM, Mathew Topper wrote:
> Dear matplotlib-users,
>
> I have a spatial data set that has coded values for each cell, which are
> limited to just a few numbers, ie -, 0, 100, and . I would like
> to display this data with a plot similar to pcolor, but I don't want a
> colorbar, I want a legend showing the colors for each code and an
> explanation for what each code represents. I would like to be able to
> choose a subset of the codes as well, for example just plotting the 0
> and 100 codes and ignoring the - and  codes.
>
> I have seen a few similar attempts that used BoundaryNorm, but I don't
> want to show a range of values I just want to set colors for a few
> explicit values. Those examples also had a colorbar and, as I said, I
> would prefer a legend.
>
> Can anyone offer any tips?

For the plot itself you can use pcolor if your data are on a 
quadrilateral grid, or a PathCollection or PolyCollection otherwise. 
For the legend, you can use proxy artists:

http://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist

Eric

>
> Thanks
>
> Mat
>


--
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] 2D array plot picking explicit values to colour and legend

2012-04-09 Thread Mathew Topper

Hi Eric, thanks for the tip about the legend.

Regarding the data, assuming i am using pcolor, am I right in thinking 
that using Boundarynorm would be the best way to control the colors for 
each code?


Thanks

Mat

On 04/09/2012 06:26 PM, Eric Firing wrote:

On 04/09/2012 02:22 AM, Mathew Topper wrote:

Dear matplotlib-users,

I have a spatial data set that has coded values for each cell, which are
limited to just a few numbers, ie -, 0, 100, and . I would like
to display this data with a plot similar to pcolor, but I don't want a
colorbar, I want a legend showing the colors for each code and an
explanation for what each code represents. I would like to be able to
choose a subset of the codes as well, for example just plotting the 0
and 100 codes and ignoring the - and  codes.

I have seen a few similar attempts that used BoundaryNorm, but I don't
want to show a range of values I just want to set colors for a few
explicit values. Those examples also had a colorbar and, as I said, I
would prefer a legend.

Can anyone offer any tips?

For the plot itself you can use pcolor if your data are on a
quadrilateral grid, or a PathCollection or PolyCollection otherwise.
For the legend, you can use proxy artists:

http://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist

Eric


Thanks

Mat



--
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users



--
Dr. Mathew Topper
Institute for Energy Systems
School of Engineering
The University of Edinburgh
Faraday Building
The King's Buildings
Edinburgh EH9 3JL
Tel: +44 (0)131 650 5570
School fax: +44 (0)131 650 6554
mathew.top...@ed.ac.uk 
http://www.see.ed.ac.uk 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
--
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] 2D array plot picking explicit values to colour and legend

2012-04-09 Thread Eric Firing
On 04/09/2012 08:17 AM, Mathew Topper wrote:
> Hi Eric, thanks for the tip about the legend.
>
> Regarding the data, assuming i am using pcolor, am I right in thinking
> that using Boundarynorm would be the best way to control the colors for
> each code?

Mat,

I think BoundaryNorm is overkill and/or awkward for your case.  It 
sounds like you don't have ordinary values, but rather a set of labels 
that happen to be integers.  I would use a ListedColormap and then use 
sequential integers as the C values to index directly into the colormap:

C = np.array([[0,1,2],[2,0,1]])
import matplotlib.colors as mcolors
cmap = mcolors.ListedColormap(['r', 'g', 'lightgray'])
pcolor(C, cmap=cmap, norm=mcolors.NoNorm())

Of course you would need to map your sequence of numbers (-, 0, ...) 
to a sequence of integers starting at zero.

The key point is that the NoNorm() instance leaves your original C 
values alone, and since they are integers, they are then used directly 
as indices.

You could also make your own mcolors.Normalize subclass which would 
process your labels and return either a float in the 0-1 range, or an 
integer for direct indexing.

When you need only a very few colors, the ListedColormap with direct 
indexing is nice because it allows you to specify those colors using any 
valid color specification method.


Eric



>
> Thanks
>
> Mat
>
> On 04/09/2012 06:26 PM, Eric Firing wrote:
>> On 04/09/2012 02:22 AM, Mathew Topper wrote:
>>> Dear matplotlib-users,
>>>
>>> I have a spatial data set that has coded values for each cell, which are
>>> limited to just a few numbers, ie -, 0, 100, and . I would like
>>> to display this data with a plot similar to pcolor, but I don't want a
>>> colorbar, I want a legend showing the colors for each code and an
>>> explanation for what each code represents. I would like to be able to
>>> choose a subset of the codes as well, for example just plotting the 0
>>> and 100 codes and ignoring the - and  codes.
>>>
>>> I have seen a few similar attempts that used BoundaryNorm, but I don't
>>> want to show a range of values I just want to set colors for a few
>>> explicit values. Those examples also had a colorbar and, as I said, I
>>> would prefer a legend.
>>>
>>> Can anyone offer any tips?
>> For the plot itself you can use pcolor if your data are on a
>> quadrilateral grid, or a PathCollection or PolyCollection otherwise.
>> For the legend, you can use proxy artists:
>>
>> http://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist
>>
>> Eric
>>
>>> Thanks
>>>
>>> Mat
>>>
>>
>> --
>> For Developers, A Lot Can Happen In A Second.
>> Boundary is the first to Know...and Tell You.
>> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
>> http://p.sf.net/sfu/Boundary-d2dvs2
>> ___
>> Matplotlib-users mailing list
>> Matplotlib-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>
> --
> Dr. Mathew Topper
> Institute for Energy Systems
> School of Engineering
> The University of Edinburgh
> Faraday Building
> The King’s Buildings
> Edinburgh EH9 3JL
> Tel: +44 (0)131 650 5570
> School fax: +44 (0)131 650 6554
> mathew.top...@ed.ac.uk 
> http://www.see.ed.ac.uk 
>
>
>
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
>
>
> --
> For Developers, A Lot Can Happen In A Second.
> Boundary is the first to Know...and Tell You.
> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
> http://p.sf.net/sfu/Boundary-d2dvs2
>
>
>
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users



--
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users