How to save pcolormesh size as a numpy array - saving data form?

It seems that I have some problems with saving the graph created with matplotlib.pcolormesh(). As far as I know, pcolormeshconverts the input matrix using a color map. The color palette displays the RGB value for each entry in the matrix and displays it.

What in my head will look like

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.axis('off')
plt.show()
raw_input("sadas")

convert = plt.get_cmap(cm.jet)
norm = matplotlib.colors.Normalize(vmin=0,vmax=1)
numpy_output_static = convert(norm(data.T))
plt.imshow(numpy_output_static,cmap = cm.jet, aspect = 'auto')
plt.show()
raw_input("asds")

enter image description here

enter image description here

The problem is that the numpy array of data represented as a graph is not like the first graph shows. I need numpy to have the data that represents the graph, so if I wanted to build it, I would get an identical image as the first, and the shape of the numpy array should be similar to the input that was used in section 1.

, , , .

, , .

matplotlib, .

0
2

-1.828067 22.70058. vmin=0 vmax=1. , 1, imshow.

norm = matplotlib.colors.Normalize(vmin=-1.828067,vmax=22.70058)

.

, , , ,

plt.imshow(data.T,cmap = cm.jet, aspect = 'auto')
+1

, :

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

min_max_scaler = preprocessing.MinMaxScaler(feature_range=(0, 1))

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.axis('off')
plt.show()
#raw_input("sadas")

convert = plt.get_cmap(cm.jet)
data = min_max_scaler.fit_transform(data)
print data.min()
print data.max()
numpy_output_static = convert(data.T)
plt.imshow(numpy_output_static, aspect = 'auto')
plt.show()
#raw_input("asds")

, , , , . sklearn , .

cmap.

:

enter image description here

0

Source: https://habr.com/ru/post/1677434/


All Articles