I am currently trying to create a numpy which is similar to a plot...
MVCE:
#
# MVCE version
#
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
import ast
import urllib
import os
import sys
from os import listdir
from os.path import isfile, join
min_max_scaler = preprocessing.MinMaxScaler(feature_range=(0,1))
def make_plot_store_data(name,interweaved,static,delta,delta_delta,isTrain,isTest,isDev):
print static.shape
print type(static)
print np.min(static)
print np.max(static)
fig = plt.figure()
librosa.display.specshow(static.T,sr=16000,x_axis='frames',y_axis='mel',hop_length=160,cmap=cm.jet)
#plt.axis('off')
plt.title("log mel power spectrum of " + name)
plt.colorbar(format='%+02.0f dB')
plt.tight_layout()
if isTrain == True:
plt.figure()
convert = plt.get_cmap(cm.jet)
numpy_output_static = convert(min_max_scaler.fit_transform(np.flipud(static.T)))
plt.imshow(numpy_output_static,aspect = 'auto')
plt.show()
raw_input("sadas")
link = "https://gist.githubusercontent.com/Miail/51311b34f5e5333bbddf9cb17c737ea4/raw/786b72477190023e93b9dd0cbbb43284ab59921b/feature.txt"
f = urllib.urlopen(link)
#Loading data
temp_list = []
for line in f:
entries = 0
data_splitted = line.split()
if len(data_splitted) == 2:
file_name = data_splitted[0]
else:
entries = 1+entries
if data_splitted[-1] == ']':
temp_list.extend([ast.literal_eval(i) for i in data_splitted[:-1]])
else:
temp_list.extend([ast.literal_eval(i) for i in data_splitted])
#Reformatting data
dimension = 120
entries = len(temp_list)/dimension
data = np.array(temp_list)
interweaved = data.reshape(entries,dimension)
static =interweaved[:,:-80]
delta =interweaved[:,40:-40]
delta_delta =interweaved[:,80:]
plot_interweaved = data.reshape(entries*3,dimension/3)
print static.shape
print delta.shape
print delta_delta.shape
make_plot_store_data(file_name,plot_interweaved,static,delta,delta_delta,True,False,False)
Running this code creates two plot.. First being the version plotted using librosa, and the other one using the colormap cm.jet to extract each pixel values.
Problem is that both plot aren't the same even though what is being performed is the same. librosa.display.specshow
make use of pcolormesh
to make the plot, so it should not bias anything.
But the plots i see is:
Here is the actual plot created with librosa:
And the recreated plot:
What is wrong?