SiegeLord / RustGnuplot

A Rust library for drawing plots, powered by Gnuplot.
GNU Lesser General Public License v3.0
407 stars 46 forks source link

Move captions around? #20

Open ArtemGr opened 7 years ago

ArtemGr commented 7 years ago

I wonder if it's possible to move the captions around?

In gnuplot that would be "set key left top". cf. http://stackoverflow.com/questions/12208054/gnuplot-legend-overlaps-graph

SiegeLord commented 7 years ago

The set_legend method has a whole bunch of options. You can specify the location of the legend using the first two arguments, e.g.:

.set_legend(Graph(0.5),
            Graph(-0.2),
            &[Horizontal, Placement(AlignCenter, AlignTop), Title("Legend Title")],
            &[TextAlign(AlignRight)]);
ArtemGr commented 7 years ago

Thanks for the hint.

The legend is not quite the caption, though. 1) The captions are automatically aligned by the gnuplot, which is much more convenient than trying to move the legend "by hand". 2) The captions show the sample of the line they're related to. 3) They share the color of the line. 4) There is a separate caption for every line. Whereas there is only one legend. I've just tried

    .set_legend (Graph (0.5), Graph (-0.2), &[Horizontal, Placement (AlignCenter, AlignTop), Title ("Legend Title")], &[TextAlign (AlignRight)])
    .set_legend (Graph (0.8), Graph (-0.4), &[Horizontal, Placement (AlignCenter, AlignTop), Title ("Legend Title 2")], &[TextAlign (AlignRight)])

and only the second legend is displayed. 5) Not to mention that one might need both the captions and the legend.

In other words, duh.

ArtemGr commented 7 years ago

Anyway, I'm going to use the gnuplot directly, so NP.

SiegeLord commented 7 years ago

Interesting, I've never heard of this feature before. Maybe it can be added one day. You can actually dump the generated gnuplot commands from this library and edit in the bits you're interested in, in principle.