Bug report

Let me know if this is not the appropriate way to report bugs.

Here is the example code:

import numpy as N
import matplotlib
matplotlib.use("TkAgg")
import pylab as PLT

x = N.array([1.,2.,3.,4.,5.])
y = N.array([2.2,3.3,4.4,5.5,6.6])
PLT.figure(1)
PLT.clf()
PLT.hold(False)
PLT.plot(x,y,'+',color='k',linestyle='--')

***Symbol is blue (wrong), line is dashed and black (right)

PLT.plot(x,y,'+',color=[0,0,0],linestyle='--')

***Same error as above

PLT.plot(x,y,'+r',linestyle='--')

***Works correctly (symbol and line are red)

PLT.axis([0.0,6.0,0.0,7.0])
PLT.xlabel('X Label',fontsize=18)
PLT.ylabel('Y label',fontsize=18)
PLT.title('TITLE',fontsize=24)
PLT.hold(True)

PLT.plot(x+0.1,y-0.2,'+r')

***ERROR: resets axis limits (is this an error? Note hold is on)

PLT.axis([0.0,6.0,0.0,7.0])

***Restores manual axes limits

matplotlib.__version__

'0.87.2'

N.__version__

'0.9.6'

-Tony

···

--
Tony Mannucci
Supervisor, Ionospheric and Atmospheric Remote Sensing Group
  Mail-Stop 138-308, Tel > (818) 354-1699
  Jet Propulsion Laboratory, Fax > (818) 393-5115
  California Institute of Technology, Email > Tony.Mannucci@...369...
  4800 Oak Grove Drive, http://genesis.jpl.nasa.gov
  Pasadena, CA 91109

Let me know if this is not the appropriate way to report

    > bugs. Here is the example code:

This is a good way to report them, but none of these are bugs :slight_smile:

    > import numpy as N import matplotlib matplotlib.use("TkAgg")
    > import pylab as PLT

    > x = N.array([1.,2.,3.,4.,5.]) y =
    > N.array([2.2,3.3,4.4,5.5,6.6]) PLT.figure(1) PLT.clf()
    > PLT.hold(False) PLT.plot(x,y,'+',color='k',linestyle='--')

    > ***Symbol is blue (wrong), line is dashed and black (right)

A single line object can have a linestyle and a marker and their
colors are independent. The "color" kwarg applies to the linestyle.
The markerfacecolor and markeredgecolor kwargs control the marker
color.

    > PLT.plot(x,y,'+',color=[0,0,0],linestyle='--')

    > ***Same error as above

Same explanation.

    > PLT.plot(x,y,'+r',linestyle='--')

    > ***Works correctly (symbol and line are red)

The format color string applies to the marker or line -- this is
different than the kwargs.

    > PLT.axis([0.0,6.0,0.0,7.0]) PLT.xlabel('X
    > Label',fontsize=18) PLT.ylabel('Y label',fontsize=18)
    > PLT.title('TITLE',fontsize=24) PLT.hold(True)

    > PLT.plot(x+0.1,y-0.2,'+r')

    > ***ERROR: resets axis limits (is this an error? Note hold is
    > on)

"hold" controls whether multiple lines are plotted on the same axes or
whether the axes is cleared with successive plots. To disable
autoscaling, use

  ax.set_autoscale_on(False)

    > PLT.axis([0.0,6.0,0.0,7.0])

    > ***Restores manual axes limits

As it should.

Thanks,
JDH

John,

Thanks for the answer.

My prime mistake was to assume that matlab behavior is mimicked in matplotlib. (I am not saying it should be!). matlab has a Line object and this includes the markers. So, what I called "bugs" was based on a false expectation. The matlab version of the code will produce lines and symbols of the same color.

I will spend more time with the matplotlib manual and learn the differences with matlab, and make progress that way.

Thanks again,

-Tony

···

PLT.hold(False)
PLT.plot(x,y,'+',color='k',linestyle='--')

    > ***Symbol is blue (wrong), line is dashed and black (right)

A single line object can have a linestyle and a marker and their
colors are independent. The "color" kwarg applies to the linestyle.
The markerfacecolor and markeredgecolor kwargs control the marker
color.

--
Tony Mannucci
Supervisor, Ionospheric and Atmospheric Remote Sensing Group
  Mail-Stop 138-308, Tel > (818) 354-1699
  Jet Propulsion Laboratory, Fax > (818) 393-5115
  California Institute of Technology, Email > Tony.Mannucci@...369...
  4800 Oak Grove Drive, http://genesis.jpl.nasa.gov
  Pasadena, CA 91109

John, Thanks for the answer.

    > My prime mistake was to assume that matlab behavior is
    > mimicked in matplotlib. (I am not saying it should
    > be!). matlab has a Line object and this includes the
    > markers. So, what I called "bugs" was based on a false
    > expectation. The matlab version of the code will produce
    > lines and symbols of the same color.

    > I will spend more time with the matplotlib manual and learn
    > the differences with matlab, and make progress that way.

Hmm, I didn't know matlab behaved this way. I know matlab does have
color, markerfacecolor and margeredgecolor, so I assumed that they
would be controlled independently. So the behavior is

  set(l, 'color', 'red')

and both the linestyle and markercolor are changed?

JDH

John,

They do behave independently. This is about default behavior. Here are some examples (unverified), that assume some standard matplotlib rc file.

Ex 1:
No color specified.
MPL and matlab result: both line and marker edge have same default color.

Ex 2:
Set the color with the plot command, e.g. 'r+-' string.
matlab result: both marker and line are red.
MPL result: line is red, marker remains default blue.

Ex 3:
Set colors explicitly, e.g. 'ro-', 'markerfacecolor'=[0,1,0]
matlab and MPL result: line is red, marker face is green. I **believe** that in MPL the marker edge will remain default blue, since it is not set explicitly. In matlab, the marker edge will pick up the red line color.

Both approaches are reasonable, one simply has to know what to expect. In my case, being somewhat new to MPL, I was quite confused by how Ex 2 worked in MPL. Now I know better. The matlab approach requires somewhat less typing typically.

-Tony

···

At 8:23 AM -0500 6/29/06, John Hunter wrote:

    > John, Thanks for the answer.

    > My prime mistake was to assume that matlab behavior is
    > mimicked in matplotlib. (I am not saying it should
    > be!). matlab has a Line object and this includes the
    > markers. So, what I called "bugs" was based on a false
    > expectation. The matlab version of the code will produce
    > lines and symbols of the same color.

    > I will spend more time with the matplotlib manual and learn
    > the differences with matlab, and make progress that way.

Hmm, I didn't know matlab behaved this way. I know matlab does have
color, markerfacecolor and margeredgecolor, so I assumed that they
would be controlled independently. So the behavior is

  set(l, 'color', 'red')

and both the linestyle and markercolor are changed?

JDH

--
Tony Mannucci
Supervisor, Ionospheric and Atmospheric Remote Sensing Group
  Mail-Stop 138-308, Tel > (818) 354-1699
  Jet Propulsion Laboratory, Fax > (818) 393-5115
  California Institute of Technology, Email > Tony.Mannucci@...369...
  4800 Oak Grove Drive, http://genesis.jpl.nasa.gov
  Pasadena, CA 91109