Skip to content

enable assignment of "Download plot as a png" value to variable #2889

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

Open
yasirroni opened this issue Nov 10, 2020 · 2 comments
Open

enable assignment of "Download plot as a png" value to variable #2889

yasirroni opened this issue Nov 10, 2020 · 2 comments
Labels
feature something new P3 backlog

Comments

@yasirroni
Copy link

yasirroni commented Nov 10, 2020

Bug (or Feature Request?):

I want to get the annotated image after I used drawrect. The only possible way, for now, is using the Download plot as a png button, save it on pc, read it. Is there a straightforward way to do that?

I mark it as a bug (or maybe it's the intended behavior by the developer) because fig.to_image(format="png", engine="kaleido") return the original image, not the annotated one.

Note: I'm using a jupyter notebook

import plotly.graph_objects as go
fig = go.Figure(data=go.Bar(y=[2, 3, 1]))
config = dict({    
    'modeBarButtonsToAdd':[
        'drawrect',
        'eraseshape',
    ],
    'modeBarButtonsToRemove':[
        'toggleSpikelines','hoverCompareCartesian'
    ]
})
fig.show(config=config)

original)

do some annotations...

annotated

then run:

import numpy as np
import cv2
import matplotlib.pyplot as plt
annotate_image = fig.to_image(format="png", engine="kaleido")
nparr = np.frombuffer(annotate_image, np.uint8)
img_numpy = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
plt.imshow(img_numpy[...,::-1])

saved_image

The plt.imshow(img_numpy[...,::-1]) will show the original image, not the annotated image. How to use fig.to_image(format="png", engine="kaleido") to include the annotation of drawrect? Or any workaourd?

@gvwilson
Copy link
Contributor

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson

@yasirroni
Copy link
Author

Okay, let's make it simple.

Please support Download plot as png as method for the figure.

image

Something like:

annotate_image = fig.download_image(format="png", engine="kaleido")

SInce:

annotate_image = fig.to_image(format="png", engine="kaleido")

Only convert original plot without the annotation.

@gvwilson gvwilson self-assigned this Jun 19, 2024
@gvwilson gvwilson reopened this Jun 19, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added the P3 backlog label Aug 12, 2024
@gvwilson gvwilson changed the title Assign "Download plot as a png" value to Variable enable assignment of "Download plot as a png" value to variable Aug 12, 2024
@gvwilson gvwilson added the feature something new label Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new P3 backlog
Projects
None yet
Development

No branches or pull requests

2 participants