Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#61 Allow filledcurve color to based on whether above/below axis

closed-accepted
Petr Mikulik
None
5
2004-07-30
2004-04-01
Steve Weiss
No

It would be nice if you could specify the two colors for a
filledcurve; One color if the area is above the x-axis, a
second if the area is below the x-axis.

For example, if charting a stock during the day, you
could make the "positive" fill area green and
the "negative" fill area red.

Discussion

1 2 > >> (Page 1 of 2)
  • Petr Mikulik
    Petr Mikulik
    2004-04-08

    Logged In: YES
    user_id=31505

    Make your graph by plotting the same curve twice, and
    probably with this trick:

    plot (f(x)>g(x) ? f(x) : 1/0)

     
  • Petr Mikulik
    Petr Mikulik
    2004-04-08

    • assigned_to: nobody --> mikulik
     
  • Ethan Merritt
    Ethan Merritt
    2004-04-29

    Logged In: YES
    user_id=235620

    Give this patchset a try. It adds new modifiers "above" and
    "below" to the filledcurve style. They apply only to the
    case of explicit bounds. For example:
    plot 'data' with filledcurve above y1=3.4

    I have not done much testing of this code. Please check
    whether it does what you want, and if so give it a thorough
    workout. In particular I did not do anything special for
    curves that go out of range. It may just work, or it may
    need special-case code added.

     
  • Steve Weiss
    Steve Weiss
    2004-04-29

    Logged In: YES
    user_id=939458

    It's different, but not correct. it looks like you figuring out
    the bounding area to fill, you draw a line from the current
    point to the previous data point as opposed to the current
    point to the previous point where the x-axis was crossed (if
    that makes sense).

    I have attached a sample image for you to look at. Please let
    me know if you need a copy of my test script.

    Thanks for all the help!
    Steve

     
  • Steve Weiss
    Steve Weiss
    2004-04-29

    Sample graph after applying 28apr2004 patch

     
    Attachments
  • Ethan Merritt
    Ethan Merritt
    2004-04-29

    Logged In: YES
    user_id=235620

    Heh. A minor, but dramatic, oversight on my part. Here's a
    revised patchset that might actually work.

     
  • Ethan Merritt
    Ethan Merritt
    2004-04-29

    revised patchset implementing requested feature

     
  • Petr Mikulik
    Petr Mikulik
    2004-04-30

    Logged In: YES
    user_id=31505

    I like this patch!

    I would propose to submit it to cvs, as it is a valuable
    feature for the curretion version of gnuplot.

    Another great enhancement would be
    plot 'a.dat' using 1:2:3 with filledcurve
    where the filled area would be in between y-points of
    columns 2 and 3.
    Could you please try to implement this as well?

     
  • Ethan Merritt
    Ethan Merritt
    2004-04-30

    Logged In: YES
    user_id=235620

    Petr wrote>
    > I would propose to submit it to cvs, as it is a valuable
    > feature for the curretion version of gnuplot.

    Hold off a bit. Steve claims to have found a case where my
    patch gets the sidedness wrong, although so far I have not
    been able to reproduce the problem. We're pursuing the
    discrepancy in private Email.

    >Another great enhancement would be
    > plot 'a.dat' using 1:2:3 with filledcurve
    >where the filled area would be in between
    > y-points of columns 2 and 3.

    The ability to fill an area between two curves has been
    requested a number of times before. I thought there was an
    existing RFE here on SourceForge, but I can't see it now.
    Anyhow, this would be a much more extensive change than the
    simple bounding-line patch I gave here. The code to draw
    filled polygons bounded by a line was already present. All
    I had to do was make sure that any line segment crossing the
    bounding line is broken into two pieces so that no single
    polygon ever spans both sides of the boundary.

    By contrast, drawing a filled region bounded by two
    arbitrary curves requires storing twice as much information
    for the plot. As you show, it requires an additional input
    column. Or, I suppose, two bounding equations in the case of
    'set style function filledcurve'. This means that it is
    effectively a new plot style, and would require adding new
    code in a lot of places. I think this would be fairly easy,
    but still it would be a bigger project than my simple patch
    here. Certainly it goes way beyond what could be considered
    a bug-fix for version 4.0

    So yeah, I agree it would be a very nice, fairly
    straightforward addition. But it can wait until the next
    round of development.

     
  • Petr Mikulik
    Petr Mikulik
    2004-04-30

    Logged In: YES
    user_id=31505

    > 'set style function filledcurve'.

    No, this I would not support, currently you cannot use
    "using" for functions.
    However,
    'a.dat' using 1:2:(sin($1))
    would work.

    > By contrast, drawing a filled region bounded by two
    > arbitrary curves requires storing twice as much information
    > for the plot.

    I don't think that's difficult.
    At graphics.c:1832:
    for (i = 0; i < plot->p_count; i++) {
    there is
    x = map_x(plot->points[i].x);
    y = map_y(plot->points[i].y);
    so plotting wrt 3 columns would have
    y2 = map_y(plot->points[i].z);
    ...I think that parser for plotting wrt 3 columns puts the
    3rd column number into z.

    Then the INRANGE/OUTRANGE cases would have to go in between
    crossing points in between those 2 curves using max(y,y2),
    and make a circle -- i.e., instead of finish_filled_curve(),
    it should do the 2nd round back using values min(y,y2).

     
1 2 > >> (Page 1 of 2)