About 898,000 results
Open links in new tab
  1. matplotlib - How can I display an image in Python that's …

    Sep 28, 2020 · It turns out matplotlib.image.imread() can't take a BytesIO object as a parameter, but the following code worked for me: from PIL import Image img = …

  2. How to matplotlib plt.savefig() to a io.BytesIO buffer

    Aug 28, 2023 · You can just pass a io.BytesIO() to plt.savefig() as first parameter. Note that format defaults to "png", but best practice is to explicitly specify it. plt.savefig(bio, dpi=250, …

  3. Using io.BytesIO() with Python

    Instead of this, you can read and write to a file-like object. This acts like a file, but it’s just sitting in memory. You can save data to this file, pass it around, and it never gets written anywhere. In …

  4. matplotlib.pyplot.savefig — Matplotlib 3.10.3 documentation

    Save the current figure as an image or vector graphic to a file. The available output formats depend on the backend being used. A path, or a Python file-like object, or possibly some …

  5. Python bytes

    In this tutorial of Python Examples, we have learned what a bytes object is in Python, how to initialize a bytes object, how to make conversions to and fro with other data types, etc.

  6. [ENH]: Figure to image bytes · Issue #23319 · matplotlib/matplotlib

    Jun 21, 2022 · Maybe like a .to_image() method. plt. plot (y) with io. BytesIO () as buffer: # use buffer memory plt. savefig (buffer, format='png') buffer. seek (0) image = buffer. getvalue () …

  7. python - how to save a pylab figure into in-memory file which can …

    Dec 22, 2011 · def fig2img(fig): """Convert a Matplotlib figure to a PIL Image and return it""" import io buf = io.BytesIO() fig.savefig(buf) buf.seek(0) img = Image.open(buf) return img Then I can …

  8. 5 Best Ways to Convert Python Bytes to Image

    Feb 23, 2024 · Method 3: Using matplotlib. matplotlib is primarily used for creating static, interactive, and animated visualizations in Python. However, it can also be used to convert a …

  9. savefig and StringIO error on Python3 - matplotlib-users

    Nov 1, 2014 · However, the following piece of code does not work with matplotlib/Python3 (while it should work with Python2). The error is the following on TypeError: string argument expected, …

  10. convert_to_bytes Function + PIL Image Viewer

    The key to the program is the function "convert_to_bytes" which takes a filename or a bytes object and converts (with optional resize) into a PNG formatted bytes object that can then be passed …

Refresh