Menu

#2719 colors ignored: plot ... with circles lc variable with SVG output

None
closed-fixed
nobody
None
2024-12-21
2024-06-29
Anonymous
No

Hi,
at first, thanks for providing and maintaining gnuplot all those years.

When switching from GNUPLOT 4.6 patchlevel 2 (CentOS 7) to GNUPLOT 5.2 patchlevel 2 (SLES 15) (same for GNUPLOT 6.0 patchlevel 1), the SVG output file no longer used the colors defined using
e.g. "set style line 1 lt 1 lc rgb ..." when plotting using "plot ... with circles lc variable"

Expected behaviour:

  • colors from "style line" are used
    Current behaviour:
  • random (?) colors are used
2 Attachments

Discussion

  • Reiner Steib

    Reiner Steib - 2024-06-29
    • Attachments has changed:

    Diff:

    --- old
    +++ new
    @@ -1 +1,2 @@
    +pie-all-versions.png (81.8 kB; image/png)
     pie.gp (1.7 kB; application/octet-stream)
    
    • Group: -->
    • Priority: -->
     
  • Reiner Steib

    Reiner Steib - 2024-06-29

    Attached sreenshot of pie-all-versions.png: version 4, 5, 6.

     
  • Reiner Steib

    Reiner Steib - 2024-06-29

    Attached: pie-chart-v4.svg - expected behavior in Version 4

     
  • Reiner Steib

    Reiner Steib - 2024-06-29

    Attached: pie-chart-v5.svg - unexpected behavior in Version 5

     
  • Reiner Steib

    Reiner Steib - 2024-06-29

    Attached: pie-chart-v6.svg - unexpected behavior in Version 6

     
  • Ethan Merritt

    Ethan Merritt - 2024-06-30

    The terminal type is not relevant here.
    The issue is the deprecation of allowing a bare numeric value to be interpreted as a line color.

    Short answer:

    • To make your existing script work in gnuplot version 5, add the command
      set style increment userstyles
    • To make it work in version 6 would require something else (see below)

    Long answer:

    Gnuplot places a strong emphasis on preserving backward compatibility. But sometimes the addition of new features and code paths makes it impractical to preserve old behavior in cases where the old command did not provide enough information to unambiguously decide which of several newer options is appropriate. So we do allow some breakage across a major version upgrade, while attempting to mitigate the effects by providing a command to emulate the previous behavior.

    gnuplot 3: In very old gnuplot versions there was no way to change properties of the default linetypes. "linetype 1" was always red, had linewidth 1.0 and associated point shape +. So back in gnuplot 3.7 and 3.8 (spanning the year 2000) if you wanted to change the properties for lines 1, 2, 3, etc you had to use a temporary "linestyle" instead. The commands in your script appear to date back to that era.

    The flexibility of assigning properties to line types has greatly increased since gnuplot version 3. This has gradually made the use of line styles (as opposed to linetypes) unnecessary, and many program features and plotting styles introduced since then assume that you are using the new more flexible linetypes rather than the older "linestyle" variants unless you explicitly say otherwise. So linetype 1 is OK, and linestyle 1 is OK, but what the user might have intended for the color of the second plot, or second variable color became ambiguous.

    gnuplot 4: Gnuplot version 4.2 (2007) introduced commands
    set style increment userstyles
    set style increment default
    that told the program whether to prefer user-defined line style N or default line type N if both "linestyle N" and "linetype N" are defined. The Nth plot color or Nth variable color would track that preference. By the time of gnuplot version 4.6 (2012) users were advised to issue the command set style increment userstyles if they wanted linestyle colors, although the program provided backward compatibility with older scripts as a configuration option. Your script falls into that category - it works in versions 4.2 to 4.6 either with or without that command.

    gnuplot 5: Version 5 (2015) switched the default to use linetypes in preference to linestyles. This is what you are seeing. In all version 5 releases your script still works, but requires an explicit set style increment userstyles to override the default.

    Gnuplot version 6 (2023) has finally deprecated this option.
    http://gnuplot.info/docs_6.0/loc602.html
    There are several ways you might change your script for version 6. One way would be to change the colors of the linetypes themselves:

    set linetype 1  lc rgb c_1
    set linetype 2  lc rgb c_2
    set linetype 3  lc rgb c_3
    set linetype 4  lc rgb c_4
    set linetype 5  lc rgb c_5
    plot ... using 1:2:3:4:5:6 with circles lc var
    

    Another way would be to provide the colors directly in the plot command:

    plot '-' using 1:2:3:4:5:6 with circles lc rgb variable
      150;50;50;0.0;30.;0x000000
      150;50;50;30.;90.;0xbbbbbb
      150;50;50;90.;180;0xdddddd
      150;50;50;180;250;0xffaa80
      150;50;50;250;360;0xaaaaee
    e
    

    missing feature/bug: Unfortunately one seemingly reasonable way does not work
    plot ... linestyle variable
    That indeed seems like a fixable oversight. Let's try to get that fixed in the next version 6 release.

     
  • Reiner Steib

    Reiner Steib - 2024-06-30

    Hi Ethan,
    thank you very much for all the explanations an the solutions.

    I will go with "set linetype 1 lc rgb c_1" etc (works for gnuplot v4, v5 and v6).

    FYI, my script dates back to 2019, on CentOS 7 with gnuplot version 4.x (https://ftp.fau.de/centos/7/os/x86_64/Packages/gnuplot-common-4.6.2-3.el7.x86_64.rpm)

    (I have serveral scripts to produce SVG images automatically. When switching from gnuplot 4.6 (CentOS 7) to gnuplot 5.2 (SLES 15) only minimal changes were necessary: this change and changing 'set timefmt x "%Y-%m"' to 'set timefmt "%Y-%m"'.)

    Bye, Reiner

     
  • Ethan Merritt

    Ethan Merritt - 2024-07-03
    • status: open --> pending-accepted
     
  • Ethan Merritt

    Ethan Merritt - 2024-12-21
    • Status: pending-accepted --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB