Skip to content Skip to sidebar Skip to footer

Matplotlib Savefig To Cstreamio Then Load The Data Into Another Matplotlib Plot/fig Python 2.7

Attempting to use matplotlib to write out to an iostream then display that data in another matplotlib plot (started by following: Write Matplotlib savefig to html). For efficiency

Solution 1:

imread interpretes the string given to it as filename. Instead one would need to supply a file-like object.

You would get such file-like object as the buffer itself. However, StringIO may not be well suited. If you use BytesIO, you can directly read in the buffer.

import io
import matplotlib.pyplot as plt

plt.plot([1,2,4,2])
plt.title("title")

buf = io.BytesIO()
plt.savefig(buf, format='png')
buf.seek(0)

imgplt = plt.imshow(plt.imread(buf))

plt.show()

Post a Comment for "Matplotlib Savefig To Cstreamio Then Load The Data Into Another Matplotlib Plot/fig Python 2.7"