Plotting problems 3.1.51+

John W. Eaton jwe at octave.org
Thu Jan 15 17:16:20 CST 2009


On 30-Sep-2008, Michael D. Godfrey wrote:

| Bug report and test file are attached.
| 
| Bug report for Octave 3.1.51+ configured for x86_64-unknown-linux-gnu
| 
| Description:
| -----------
| 
| Two problems with plotting:
| 
| 1. The grid command does not allow a second argument when the
|    first argument is "minor".  Looking at grid.m, this is a simple
|    problem, but there are choices about how to fix it.  Since
|    grid("minor") does toggle the minor grid lines as the documentation
|    says, one fix would be to change the documentation by eliminating
|    the description of the grid("minor", "on" | "off") capability.
|    Otherwise, simple change to the code will implement this.

I think this problem is fixed now in the main development sources, but
it still fails in the 3.0.x branch.  I think the following changes
should apply to the 3.0.x branch:

changeset:   8528:06e1667d7492
tag:         tip
user:        Ben Abbott <bpabbott at mac.com>
date:        Thu Jan 15 17:54:19 2009 -0500
summary:     grid.m: Correct doc-string.

changeset:   8507:cadc73247d65
user:        John W. Eaton <jwe at octave.org>
date:        Tue Jan 13 14:08:36 2009 -0500
summary:     style fixes

changeset:   8501:f729344c7362
user:        John W. Eaton <jwe at octave.org>
date:        Tue Jan 13 00:45:37 2009 -0500
summary:     grid.m: style fixes

changeset:   8424:a84d71abdc5b
user:        Doug Stewart <dastew at sympatico.ca>
date:        Wed Dec 24 16:45:11 2008 -0500
summary:     grid.m: handle minor grid option

The style fixes are not absolutely necessary, but the subsequent
patches may fail to apply cleanly without them.

| 2. I tried to use fx = line(); in order to use commands like:
|    set(fx, "linestyle", "-"); However, 2 things went wrong: first
|    the resulting plot was modified by an additional line drawn in
|    the plot.  The coordinates of the line are about (0,0) (1,0.5)
|    (1,0).  In words a line drawn in the lower left corner of the
|    plot.  also, it did not appear that the set(fx, ... ) commands
|    had the intended effect.
|   
|    The file haber.m is attached.  Currently the lines which set
|    or reference fx are commented out. So, executing the script
|    (no arguments needed) will produce the plot I expect.  Removing
|    the comment on the line that set fx (fx = line();) will produce
|    the error in the plot.  Then removing the commenting of the
|    lines that reference fx should produce the indicated changes to the 
|    plot.
| 
|    My main purpose in using fx = line();  was to manipulate the line
|    width so that plots which end up included in PDF will have thicker
|    width.  The current default width makes the lines hard to see, partcularly
|    if the plot is scaled down to an appropriate size for a paper.

In your script, you are doing

  hold on;
  ...
  fx = line();
  ...
  set(fx, "linestyle", "-");
  set(fx, "linewidth", 2);
  ...
  plot(lambda_sc, pl_sc*planck_lhbar,"1");  % in Haber arbitrary units
  plot(lambda_sc, pl_sc*wien_lhbar,"5");

Calling line without any arguments creates a line from (0,0) to (1,1)
(blame the MathWorks for that choice).

I'm not sure what the intent is, but if you want to set hte default
linestyle and linewidth, you can do

  ax = gca ();
  set (ax, "defaultlinelinewidth", 2);
  set (ax, "defaultlinelinestyle", "-");

Or, you could write

  hold on;

  h1 = plot(lambda_sc, pl_sc*planck_lhbar,"1");  % in Haber arbitrary units
  h2 = plot(lambda_sc, pl_sc*wien_lhbar,"5");

  set (h1, ...);
  set (h2, ...);

or

  h1 = line (lambda_sc, pl_sc*planck_lhbar);  % in Haber arbitrary units
  h2 = line (lambda_sc, pl_sc*wien_lhbar);

  set (h1, ...);
  set (h2, ...);

If you want to control the lines individually.

Note that hold is not necessary when using the line function to add
lines to a plot.

jwe


More information about the Bug-octave mailing list