RustGnuplot icon indicating copy to clipboard operation
RustGnuplot copied to clipboard

mutating created axes

Open ibnopcit opened this issue 9 years ago • 3 comments

This is great.

However I ran into a problem where I have to call Axes2D.points() n times, where n is known only at runtime.

I can't figure out how to use the &mut returned by fg.axes2d() -- the figure seems to have permanent ownership. I notice all the examples construct the axes without binding them to a variable.

Is there a way to mutate existing axes in an existing figure?

ibnopcit avatar Apr 19 '16 19:04 ibnopcit

Can you do:

let mut axes = fg.axes2d();
for i in 0..n
{
    axes.points(...);
}

We could add a way to grab axes after you release it, but perhaps this is sufficient?

SiegeLord avatar Apr 20 '16 02:04 SiegeLord

That results in a borrowing error on fg if you try to .show() it.

I found out you can successfully borrow a reference to fg with a function or closure:

let mut fg = Figure::new();
{
    let prep = |fg: &mut Figure| {
        let axes: &mut Axes2D = fg.axes2d();
        for i in 0..n {
            axes.points(...)
        }
    };
    prep(&mut fg);
}
fg.show();

This is an okay workaround for me, maybe call this a low priority issue.

ibnopcit avatar Apr 20 '16 14:04 ibnopcit

Wouldn't this (haven't tried exactly, but use something similar in my code) work?

let mut fg = Figure::new();
{
    let axes = fg.axes2d();
    for i in 0..n {
         axes.points(...);
    }
}
fg.show();

dvtomas avatar Dec 08 '17 12:12 dvtomas