Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiplot fails if it is the first plot in the script #30

Open
Rapidice opened this issue Nov 1, 2024 · 2 comments
Open

Multiplot fails if it is the first plot in the script #30

Rapidice opened this issue Nov 1, 2024 · 2 comments

Comments

@Rapidice
Copy link
Contributor

Rapidice commented Nov 1, 2024

When a script has a multiplotas it's very first plot, the plot produced it's a regular plot, the second plot overwrites the first one withouth any error indication:

Let's use this small example:

import numpy as np
import gnuplotlib as gp
th = np.linspace(0, 2*np.pi, 100)
x1 = np.cos(th)
y1 = np.sin(th)
x2 = 2*np.cos(th)
y2 = 3*np.sin(th)

gp.plot(
    ((
        x1,
        y1,
        dict(
            legend = "Circle",
            _with = "linespoints dt 4 pt 4",
        )),
     dict(
         title="Circle",
         xlabel="X",
         ylabel="Y",
     )),
    ((
        x2,
        y2,
        dict(
            legend = "Ellipse",
            _with = "linespoints dt 4 pt 4",
        )),
     dict(title="Ellipse",
         xlabel="X",
         ylabel="Y",
     )),
    _wait=True,
    square=True,
    multiplot="layout 2,1"
)

This produces the following output:

multiplot_1

As we see, the Ellipse plot has overwritten the Circle plot, totally ignoring the multiplot argument. No warnings, no errors. Just silently ignores the option.

However, if we add a regular plot before the multiplot:

import numpy as np
import gnuplotlib as gp
th = np.linspace(0, 2*np.pi, 100)
x1 = np.cos(th)
y1 = np.sin(th)
x2 = 2*np.cos(th)
y2 = 3*np.sin(th)
# Dummy plot so multiplot doesn't fail
gp.plot(
    np.sin(th),
    np.cos(th),
    _wait=True,
)

gp.plot(
    ((
        x1,
        y1,
        dict(
            legend = "Circle",
            _with = "linespoints dt 4 pt 4",
        )),
     dict(
         title="Circle",
         xlabel="X",
         ylabel="Y",
     )),
    ((
        x2,
        y2,
        dict(
            legend = "Ellipse",
            _with = "linespoints dt 4 pt 4",
        )),
     dict(title="Ellipse",
         xlabel="X",
         ylabel="Y",
     )),
    _wait=True,
    square=True,
    multiplot="layout 2,1"
)

We get the desired output

multiplot_2

One curious effect is that this only works if _wait=True is provided in the Dummy Plot

@Rapidice
Copy link
Contributor Author

Rapidice commented Nov 1, 2024

Further experimentation brings to surface the following strange behaviours:

  • Zooming is only enabled in the last subplot of the multiplot
  • Zooming in erases all subplot but the last, who now occupies the entire frame.
  • The dummy plot technique is useless in IPython repls, could not get a single multiplot after several tries or tweaks.

This behavior occurs both with qt and wxt as interactive terminals.

@dkogan
Copy link
Owner

dkogan commented Nov 2, 2024

Hi. Thanks for the report. I don't remember all the gory details here, but I just looked VERY briefly. Some preliminary answers:

  • I see what you are reporting with x11
  • I believe this worked previously with interactive plots, and I DO see it work with wxt right now. It's inconsistent, however. If I add hardcopy="/tmp/tst.gp", ascii=True, and then execute the result, I see the two plots in the x11 terminal.
  • When I say it "worked" previously, I mean that you could see the two plots next to each other in an interactive terminal, but any kind of interactive anything (pan, zoom, ruler, measure stuff) never worked. This is a limitation of gnuplot, I believe.
  • Using a noninteractive terminal (hardcopy="/tmp/tst.pdf") worked before and works now. This is how I always use this feature, since the full interactivity doesn't work anyway.

I suspect there's nothing here to fix, other than adding what I just said to the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants