8000 Figure.get_png_data() method not working · Issue #1648 · bqplot/bqplot · GitHub
[go: up one dir, main page]

Skip to content

Figure.get_png_data() method not working #1648

@giswqs

Description

@giswqs

I tried to use the get_png_data method to save the figure as a png programmatically, but it has has no effect. No png is created.

https://bqplot.github.io/bqplot/api/figure/?h=get_p#bqplot.Figure.get_png_data

Relevant issue: #963

import bqplot.pyplot as plt
import numpy as np

# Create some example data
x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)

# Plot the data
fig = plt.figure(title='Sine Wave')
plt.plot(x, y)
plt.show()

# Define a callback function to handle the PNG data
def save_png_data(png_data):
    with open('plot.png', 'wb') as f:
        f.write(png_data)
    print("PNG data saved to plot.png")

# Get the plot as PNG data and save it
fig.get_png_data(save_png_data, scale=2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0