Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot: using custom point shapes, with legend entry

Gnuplot provides a number of point styles to use in scatter plots, such as a cross, a star, a square, a circle etc. The available point types can be demonstrated by using the test command.

However, for a specific application, I need different symbols, and I need legend entries that show these symbols.

In particular, I need more than four symbols that can be plotted both in outlined and in filled state (e. g. triangles pointing left or right, parallelograms or non-square rectangles).

There are a number of approaches to use other shapes (each with some requirements towards the terminal, e. g. unicode support):

  • using PNG images
  • using set label '□' at 3,4 for each point, where □ can be replaced by any unicode character, such as ◁, ▶, ▭, ▮, etc.)
  • using plot ... with labels and providing a unicode character as a label

The problem with all of these approaches is that I can't get a proper legend (key) entry including the symbol.

I considered plotting the legend myself, but there are two reasons why I don't think that this is feasible:

  • For plotting the legend to the right of the chart (or at the lower right inside the chart), I would need to calculate the width of the legend, which depends on the font.
  • Some of the plots may include both a line and a points (like using linespoints for regular Gnuplot point types), which both have to be shown in the legend.

I am generating the Gnuplot input files programmatically, so an approach that explicitly lists all points (like the set label approach mentioned above), or that requires some calcuations, is OK.

like image 684
Martin Avatar asked Apr 24 '13 10:04

Martin


3 Answers

This won't be an answer because I'm going to tell you to change your terminal ... I know...

There is no way to add user-defined point shape in gnuplot yet, but the PostScript terminal allows about 70 different : Postscript point typeshttp://www.cp.cmc.osaka-u.ac.jp/~fumiko/tips/gnuplot_pt.jpg

In the following discussion, they state that there's no general mechanism to add user defined point type. And they come with the solution you gave in your question. https://groups.google.com/forum/?fromgroups=#!topic/comp.graphics.apps.gnuplot/in57UNxG2o0

I think a way to achieve your objective may be to

  1. Use postscript to process a "human-readable" .ps file, using default point types.
  2. "post-process" (=parse) the .ps file (it sounds like Inception to me) to change the old fashion ugly default point type into something you like, from unicode chars to home drawn shapes.
  3. ps2pdf or ps2somethingyoulike the processed .ps file.

I'm afraid I will have to face the same problem, so let the world know if you find an easier solution :)

like image 86
Pascail Avatar answered Nov 17 '22 19:11

Pascail


if anyone wants to mess with the postscritp route here is a simple example:

Each symbol is defined by name (See table in Pascali's answer) in the ps file as for example :

/BoxF  { 
      ....3 or 4 lines of terse code ...
        } def

Replace with your own definition: This is a capital letter Pi.

/BoxF {
 stroke gsave moveto    % required, this finishes prior line and moves to point
0 30 rmoveto  % nudge  symbol to get it centered properly
 /Symbol findfont 120 scalefont setfont (P) Cshow 
 grestore
     } def

This simple example may need the numbers (font size) tweaked for different types of plots..

If you want to use fonts that aren't known by your postscript interpreter you need to manually include them.

like image 2
agentp Avatar answered Nov 17 '22 19:11

agentp


Similar to Pascail's answer, you can also do this with SVG instead of Postscript.

SVG is based on XML and may or may not be easier to process than Postscript (using an XML library). It also supports unicode.

like image 2
Martin Avatar answered Nov 17 '22 19:11

Martin