[Matplotlib-users] How do i store plot data as numpy ndarray..

Carlton Banks noflaco at gmail.com
Sat May 13 07:52:17 EDT 2017


I made this tiny example code for reproducing the output:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from PIL import Image
import librosa
import librosa.display
from matplotlib import cm


fig = plt.figure(figsize=(12,4))
min = -1.828067
max = 22.70058
data =  np.random.uniform(low=min, high=max, size=(474,40))
librosa.display.specshow(data.T,sr=16000,x_axis='frames',y_axis='mel',hop_length=160,cmap=cm.jet)
plt.show()
raw_input("sadas")

convert = plt.get_cmap(cm.jet)
numpy_output_static = convert(data.T)
plt.imshow(numpy_output_static, aspect = 'auto')
plt.show()
raw_input("asds")

Which gives two different images, a random plot in first one, and a red plot in the second one. 
> Den 13. maj 2017 kl. 11.50 skrev Carlton Banks <noflaco at gmail.com>:
> 
> Hi guys.. 
> 
> I seem to have a problems with converting my plot to a numpy ndarray - 
> Such that if I made a imshow of the numpy ndarray i would see am image similar to the lmage i created.. 
> 
> librosa.display.specshow(static.T,sr=16000,x_axis='frames',y_axis='mel',hop_length=160,cmap=cm.jet)
> plt.title("log mel power spectrum of " + name)
> plt.colorbar(format='%+02.0f dB')
> plt.tight_layout()
> plt.savefig(plot+"/"+name+"_plot_static_conv.png")
> plt.show()
> This will show an image such as:
> <JPR6G.png>
> 
> 
> But if i try to store it as a numpy ndarray and then trying to plot it using this code
> convert = plt.get_cmap(cm.jet)
> numpy_output_static = convert(static.T)
> plt.imshow(numpy_output_static)
> plt.show()
> raw_input("sadas")
> I see something like this  <2WGgJ.png>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170513/97023bc9/attachment-0001.html>


More information about the Matplotlib-users mailing list