Thanks to visit codestin.com
Credit goes to github.com

Skip to content

copy/paste curves between matplotlib figures #3914

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

Closed
jhillairet opened this issue Dec 12, 2014 · 16 comments
Closed

copy/paste curves between matplotlib figures #3914

jhillairet opened this issue Dec 12, 2014 · 16 comments
Labels
New feature status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action topic: widgets/UI

Comments

@jhillairet
Copy link

First of all, thank you for all of your great work !

A recurring remark made by users coming from Matlab against the Python/Matplotlib is the fact that one cannot make simple click/copy/paste of a curve from a figure into another.

I guess this heavily depends of the backend used, or of the OS. So my question is probably naive, but anyway : would it be possible to add an interactive way to select one or more curves from a matplotlib figure and to copy/paste them into a another figure ?

It is, I think, a killing feature for many beginners/average users who used to work with matlab before.

@tacaswell tacaswell added this to the unassigned milestone Dec 12, 2014
@fariza
Copy link
Member

fariza commented Dec 15, 2014

Pretty cool idea,
I have never used Matlab so I don't know how that works.
How do you set the line to be "selectable"?
What shortcuts do you use to copy/paste?

@jhillairet
Copy link
Author

A curve is selected by clicking on it with the mouse (when the selection
mode is on). Many curves can be selected with ctrl+click.

Copy/paste is done using figure menu Edit or with usual shortcuts ctrl+c,
ctrl+v. Cut also works (ctrl+x).

Julien
Le 15 déc. 2014 17:48, "Federico Ariza" [email protected] a écrit :

Pretty cool idea,
I have never worked with Matlab so I don't know how that works.
How do you set the line to be "selectable"?
What shortcuts do you use to copy/paste?


Reply to this email directly or view it on GitHub
#3914 (comment)
.

@fariza
Copy link
Member

fariza commented Dec 15, 2014

Hmm, that might be a problem, as far as I know, to make a curve selectable, it has to have the pick radius setted, so from the beginning you have to know that you might want to copy the curve.

How do you differentiate between copy a curve and copy the entire figure?

@fariza
Copy link
Member

fariza commented Dec 15, 2014

I am just brainstorming to figure out a way to do it with the MEP22 tools, the copy figure is already in progress, so my guess would be to include this curve handling there too, but I want to have a clear workflow before even prototyping something.

@jhillairet
Copy link
Author

It is also possible to copy/paste the entire figure (the "axes" in matlab)
by selecting one axes tick or the figure background.

Also, double clicking on one object, ie a curve, a label, an axe, a title,
etc, leads to change their properties (font, color, ticks, etc). Very used
and convenient way to change figure look...
Le 15 déc. 2014 18:24, "Federico Ariza" [email protected] a écrit :

Hmm, that might be a problem, as far as I know, to make a curve
selectable, it has to have the pick radius setted, so from the beginning
you have to know that you might want to copy the curve.

How do you differentiate between copy a curve and copy the entire figure?


Reply to this email directly or view it on GitHub
#3914 (comment)
.

@fariza
Copy link
Member

fariza commented Dec 15, 2014

I understand the need and usefulness of a "properties editor".
I implemented several in the past and I use them everyday, BUT the problem is that it requires a GUI component, and with several backends to be supported it is kind of a problem.

The copy/paste is somewhat simpler, because it can be done grammatically without GUI intervention.

@tacaswell
Copy link
Member

Before this discussion goes too far, this is getting a bit out of the realm of the 'core' (as I see it) mpl mission of being a plotting library and heading towards maintaining a full gui-application (in a framework independent way).

You should look if glue (a plotting application built on top of mpl) has this sort of thing built into it already.

@fariza
Copy link
Member

fariza commented Dec 15, 2014

@tacaswell Don't worry, I am just exploring the possibility for an external tool not included in the core

@jhillairet
Copy link
Author

Dear all,

I'm coming back into this discussion. It is, I think, a killer feature for broader adoption of the Python/Matplotlib.

And by the way, is there a simple way to make a copy/paste of the full image (without having to save a file somewhere) ?

@fariza
Copy link
Member

fariza commented Jan 4, 2017

@jhillairet I use a custom tool (toolmanager) check #1987 (comment) for the basic code, for now only works on GTK3

@story645 story645 modified the milestones: unassigned, needs sorting Oct 6, 2022
@github-actions
Copy link

github-actions bot commented Oct 9, 2023

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Oct 9, 2023
@jhillairet
Copy link
Author

This issue is still important, especially for newcomers coming from the MATLAB world.

The following code allows one to make copy/paste the entire figure:
plt.rcParams['toolbar'] = 'toolmanager'

Which is already great. But copy/pasting each curve separately would be still very convenient.

@jklymak
Copy link
Member

jklymak commented Oct 9, 2023

I'm genuinely curious why this is a "killer feature" of Matlab? I used Matlab for many years, and had/have many colleagues who still do, but I've never heard of anyone cutting and pasting objects between figures.

I'd say this objectively a bad practice from the point of view of reproducibility (as is anything GUI driven). But even from a GUI-driven workflow, this seems like a clunky thing to do. Is there a video or instructions of this in action? My few minutes of googling didn't turn it up.

We could keep this open, but I'm not sure the use case is that compelling, particularly considering the effort it would take to have this available on our numerous backends.

@github-actions github-actions bot removed the status: inactive Marked by the “Stale” Github Action label Oct 11, 2023
@jhillairet
Copy link
Author

I'm working in a control room where users have to look to hundreds of different time series, and find the correlations between events in these time series. So, a lot of them copy paste curved from one figure to another to check these correlations vs time.

I agree this is generally a bad practice, but that's how they work...

@ksunden
Copy link
Member

ksunden commented Oct 13, 2023

I agree that this is niche enough that it should not be on by default or even likely baked in to the core library, but the interactivity tools already give a reasonably good way of doing this:

import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.axes import Axes
from matplotlib.lines import Line2D

import numpy as np


fig: Figure
ax1: Axes
ax2: Axes

fig, (ax1, ax2) = plt.subplots(2)

line: Line2D | None  = None

def on_pick(event):
    global line
    if isinstance(event.artist, Line2D):
        line = event.artist
        print(f"Picked line {line!r}")
    fig.canvas.draw_idle()

def on_press(event):
    print("On press: ", event.key)
    if event.key == "n":
        gen_line()
    elif event.key == "ctrl+v":
        print(line)
        if line is not None:
            ax2.plot(*line.get_data(), color=line.get_color())
    fig.canvas.draw_idle()

fig.canvas.mpl_connect("pick_event", on_pick)
fig.canvas.mpl_connect("key_press_event", on_press)

def gen_line():
    global line
    line = ax1.plot(np.cumsum(np.random.random((100))-0.5))[0]
    line.set_picker(5)
    
plt.show()

This script allows you to add lines to the top plot by pressing n and then paste with ctrl+v into the second plot.

It could be dressed up to figure out the axes dynamically, etc.
Currently you just pick and then it is held in a variable that is used on paste. (i.e. I don't actually require you ctrl-c first and didn't hook up ctrl-c/ctrl-x, but both of those would actually be quite possible.)

(Note I was originally trying to use update_from to get all the line properties copied over, not just color/data, but that also updates the transform, which we don't want to change here, so I settled for just calling plot again)

Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Oct 14, 2024
@github-actions github-actions bot added the status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. label Nov 14, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New feature status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action topic: widgets/UI
Projects
None yet
Development

No branches or pull requests

6 participants