Re: [Matplotlib-users] convert figure from color to BW/grayscale

2010-09-20 Thread Jouni K . Seppänen
Eli Brosh  writes:

> I need to prepare two versions of figures: color and BW(Black&White).
> Is there an easy way to produce just the colored version and than use some
> command or script to turn it to BW or grayscale?

For some really simple plots, and for pdf output only, you can try

rc('pdf', inheritcolor=True)

This produces a (possibly invalid) PDF file that doesn't set any colors,
and will usually be rendered in black on white. I implemented this in
response to a request to be able to inherit the current foreground color
in pdfLaTeX: if you set the color to e.g. red and include such a file,
it will be rendered in red.

This was quite some time ago, and matplotlib now has more drawing
primitives, not all of which work sensibly with this option. In some
examples you get all-black images, in some you get color in one part of
the image. But I guess this option only ever made sense for pretty
simple line drawings.

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


--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] convert figure from color to BW/grayscale

2010-09-20 Thread Benjamin Root
On Mon, Sep 20, 2010 at 1:01 PM, Eli Brosh  wrote:

> OK,
> This worked for me for turning the figure to black and white:
> After saving the figure in colors I write
>
> fig=gcf()
>
> for o in fig.findobj(matplotlib.lines.Line2D):
> o.set_color('k')
>
> for o in fig.findobj(matplotlib.text.Text):
> o.set_color('k')
>
> Than I save it as black and white.
>
> It is beyond my programming skills, but I wish we could have a built in
> function of this type.
> Perhaps as:
>
> Fig_BW=makeBW(fig)
>
> Regards,
> Eli
>
>
>
Eli,

I am glad that worked for you.  Ultimately, Friedrich's approach will make
it into a released version of matplotlib so that making a figure into a
black and white figure will be something as simple as

fig.set_gray(True)

Which, I hope, will satisfy your needs in the future.

Ben Root
--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] convert figure from color to BW/grayscale

2010-09-20 Thread Eli Brosh
OK,
This worked for me for turning the figure to black and white:
After saving the figure in colors I write

fig=gcf()

for o in fig.findobj(matplotlib.lines.Line2D):
o.set_color('k')

for o in fig.findobj(matplotlib.text.Text):
o.set_color('k')

Than I save it as black and white.

It is beyond my programming skills, but I wish we could have a built in
function of this type.
Perhaps as:

Fig_BW=makeBW(fig)

Regards,
Eli

On Mon, Sep 20, 2010 at 6:19 PM, Benjamin Root  wrote:

> On Mon, Sep 20, 2010 at 11:13 AM, Eli Brosh  wrote:
>
>> Hello Friedrich,
>> I tried your second solution:
>>
>> figure = matplotlib.figure.Figure()
>> ... do plotting ...
>> ... save as colour ...
>> figure.set_gray(True)
>> ... save as b/w ...
>>
>> but it gives me an error message:
>>  fig.set_gray(True)
>> AttributeError: 'Figure' object has no attribute 'set_gray'
>>
>> I got the same error message when trying in in pylab as:
>> fig1=gcf()
>> fig1.set_gray(True)
>>
>> and when generating the figure with the command
>> fig1 = matplotlib.figure.Figure()
>>
>> I am using matplotlib 0.99.1.1 on ubuntu 10.04/
>>
>> Is there another way to do it?
>>
>> Thanks,
>> Eli
>>
>>
> Eli, the feature is highly experimental, and is available only though fork
> of matplotlib that Friedrich made in the link he provided you.  You would
> have to install that matplotlib from its source at that link.
>
> Ben Root
>
>
--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] convert figure from color to BW/grayscale

2010-09-20 Thread Benjamin Root
On Mon, Sep 20, 2010 at 11:13 AM, Eli Brosh  wrote:

> Hello Friedrich,
> I tried your second solution:
>
> figure = matplotlib.figure.Figure()
> ... do plotting ...
> ... save as colour ...
> figure.set_gray(True)
> ... save as b/w ...
>
> but it gives me an error message:
>  fig.set_gray(True)
> AttributeError: 'Figure' object has no attribute 'set_gray'
>
> I got the same error message when trying in in pylab as:
> fig1=gcf()
> fig1.set_gray(True)
>
> and when generating the figure with the command
> fig1 = matplotlib.figure.Figure()
>
> I am using matplotlib 0.99.1.1 on ubuntu 10.04/
>
> Is there another way to do it?
>
> Thanks,
> Eli
>
>
Eli, the feature is highly experimental, and is available only though fork
of matplotlib that Friedrich made in the link he provided you.  You would
have to install that matplotlib from its source at that link.

Ben Root
--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] convert figure from color to BW/grayscale

2010-09-20 Thread Eli Brosh
Hello Friedrich,
I tried your second solution:
figure = matplotlib.figure.Figure()
... do plotting ...
... save as colour ...
figure.set_gray(True)
... save as b/w ...

but it gives me an error message:
 fig.set_gray(True)
AttributeError: 'Figure' object has no attribute 'set_gray'

I got the same error message when trying in in pylab as:
fig1=gcf()
fig1.set_gray(True)

and when generating the figure with the command
fig1 = matplotlib.figure.Figure()

I am using matplotlib 0.99.1.1 on ubuntu 10.04/

Is there another way to do it?

Thanks,
Eli


On Mon, Sep 20, 2010 at 11:14 AM, Friedrich Romstedt <
friedrichromst...@gmail.com> wrote:

> 2010/9/20 Eli Brosh :
> > Hello,
> > I need to prepare two versions of figures: color and BW(Black&White).
> > Is there an easy way to produce just the colored version and than use
> some
> > command or script to turn it to BW or grayscale?
> > I thought that converting from color to BW really means: "in all object
> in
> > the figure, turn any color that is not white to black".
> > Is there an easy way to implement this?
>
> http://github.com/friedrichromstedt/matplotlib
>
> I implemented a RC setting 'gray'.  Turn it on by setting either
> matplotlib.rcParams['gray'] = True or by setting it in your
> matplotlibrc file.
>
> You can also gray out any artist (e.g., the figure), by calling
> artist.set_gray(True).
>
> figure = matplotlib.figure.Figure()
> ... do plotting ...
> ... save as colour ...
> figure.set_gray(True)
> ... save as b/w ...
>
> If you're using pyplot or pylab, I'm not sure, but I think there is a
> function gcf() which gives you the current figure object so that you
> can turn gray on there.  pylab support should be placed on the TODO
> list, I would appreciate feedback on the preferred pylab way, since
> I'm not a pylab user at all.  I think a pylab function gray(boolean)
> would do it.
>
> It's beta, so try it out.  It's tested, though.
>
> Friedrich
>
--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] convert figure from color to BW/grayscale

2010-09-20 Thread Benjamin Root
On Mon, Sep 20, 2010 at 9:22 AM, Jonathan Slavin wrote:

> A non-matplotlib way to do this is to use ImageMagick or GraphicsMagick:
> gm convert -colorspace Gray color_image.png bw_image.png
> in GraphicsMagick or using the ImageMagick routine "convert":
> convert -colorspace Gray color_image.png bw_image.png
>
> I think it works on a wide variety of image formats.
>
> Jon
>
>
A word of warning on this approach though...  If the graphics formats are
vector-based (ps, eps, svg, etc...), then ImageMagick will destroy the
vector information in the process, even if the output format is also vector
based.  This is because ImageMagick is a raster-based library and all of its
algorithms operate upon raster data.

So, if this is for a publication, ImageMagick is not advised.

I also have another approach that allows you to convert a colormap into a
greyscale version of itself, but wouldn't work on colored lines or anything
like that.  I suggest going with Friedrich's approach.

Ben Root
--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] convert figure from color to BW/grayscale

2010-09-20 Thread Jonathan Slavin
A non-matplotlib way to do this is to use ImageMagick or GraphicsMagick:
gm convert -colorspace Gray color_image.png bw_image.png
in GraphicsMagick or using the ImageMagick routine "convert":
convert -colorspace Gray color_image.png bw_image.png

I think it works on a wide variety of image formats.

Jon

> Hello,
> I need to prepare two versions of figures: color and BW(Black&White).
> Is there an easy way to produce just the colored version and than use
> some command or script to turn it to BW or grayscale?
> I thought that converting from color to BW really means: "in all
> object in the figure, turn any color that is not white to black".
> Is there an easy way to implement this?
> 
> Thanks
> Eli


--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] convert figure from color to BW/grayscale

2010-09-20 Thread Friedrich Romstedt
2010/9/20 Eli Brosh :
> Hello,
> I need to prepare two versions of figures: color and BW(Black&White).
> Is there an easy way to produce just the colored version and than use some
> command or script to turn it to BW or grayscale?
> I thought that converting from color to BW really means: "in all object in
> the figure, turn any color that is not white to black".
> Is there an easy way to implement this?

http://github.com/friedrichromstedt/matplotlib

I implemented a RC setting 'gray'.  Turn it on by setting either
matplotlib.rcParams['gray'] = True or by setting it in your
matplotlibrc file.

You can also gray out any artist (e.g., the figure), by calling
artist.set_gray(True).

figure = matplotlib.figure.Figure()
... do plotting ...
... save as colour ...
figure.set_gray(True)
... save as b/w ...

If you're using pyplot or pylab, I'm not sure, but I think there is a
function gcf() which gives you the current figure object so that you
can turn gray on there.  pylab support should be placed on the TODO
list, I would appreciate feedback on the preferred pylab way, since
I'm not a pylab user at all.  I think a pylab function gray(boolean)
would do it.

It's beta, so try it out.  It's tested, though.

Friedrich

--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] convert figure from color to BW/grayscale

2010-09-19 Thread Eli Brosh
Hello,
I need to prepare two versions of figures: color and BW(Black&White).
Is there an easy way to produce just the colored version and than use some
command or script to turn it to BW or grayscale?
I thought that converting from color to BW really means: "in all object in
the figure, turn any color that is not white to black".
Is there an easy way to implement this?

Thanks
Eli
--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users