-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Comments
Pretty cool idea, |
A curve is selected by clicking on it with the mouse (when the selection Copy/paste is done using figure menu Edit or with usual shortcuts ctrl+c, Julien
|
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? |
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. |
It is also possible to copy/paste the entire figure (the "axes" in matlab) Also, double clicking on one object, ie a curve, a label, an axe, a title,
|
I understand the need and usefulness of a "properties editor". The copy/paste is somewhat simpler, because it can be done grammatically without GUI intervention. |
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. |
@tacaswell Don't worry, I am just exploring the possibility for an external tool not included in the core |
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) ? |
@jhillairet I use a custom tool (toolmanager) check #1987 (comment) for the basic code, for now only works on GTK3 |
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! |
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: Which is already great. But copy/pasting each curve separately would be still very convenient. |
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. |
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... |
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 It could be dressed up to figure out the axes dynamically, etc. (Note I was originally trying to use |
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! |
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.
The text was updated successfully, but these errors were encountered: