问题
I am currently not able to understand why I am not able to recreate the plot after I store the data..
import os
import sys
from os import listdir
from os.path import isfile, join
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import seaborn as sb
from matplotlib.colors import Normalize
import matplotlib
from matplotlib import cm
from PIL import Image
import librosa
import librosa.display
import ast
def make_plot_store_data(name,interweaved):
librosa.display.specshow(interweaved.T,sr=16000,x_axis='frames',y_axis='mel',hop_length=160,cmap=cm.jet)
plt.title("log mel power spectrum of interweaved " + name)
plt.colorbar(format='%+02.0f dB')
plt.savefig(plot+"/"+name+"_plot_interweaved_conv.png")
plt.show()
plt.close()
convert = plt.get_cmap(cm.jet)
numpy_output_interweawed = convert(interweaved.T)
print interweaved.shape
print numpy_output_interweawed.shape
plt.imshow(numpy_output_interweawed, interpolation='nearest')
plt.show()
raw_input("Somethign")
numpy_output_interweawed.dump(numpy_train+name+"_normalized_interweaved"+".dat")
numpy_output_interweawed_or = convert(interweaved.T)*255
numpy_output_interweawed_or.dump(numpy_train+name+"_interweaved"+".dat")
The plot showed by librosa
views the data as
But when i convert the raw data using plt.cmap(cm.jet)
and the plot it using matplotlib.pyplot
something messes up with the data, and doesn't look like the original in any way..
Edit
This is with
plt.imshow(interweaved.T,aspect = 'auto')
plt.show()
raw_input("Somethign")
It seem like the aspect ratio of the image matter - it begins to resemble the original plot, when I make the plot bigger - But why are the colors so dark...
回答1:
Nothing is wrong, everything seems to work as expected as far as I can tell without having the data or knowing the array shapes.
However, if you want to have your imshow plot look similar to the one produced by librosa, you may first consider to use an unequal aspect
plt.imshow(..., aspect="auto")
and possibly set the data range of the plot correctly using the extent
argument of imshow.
Also be aware that the plot produced by librosa is a pcolormesh
, so to truely replicate it, you might want to keep your data in the format it is (not putting it through a colormap) and use pcolormesh
to plot it.
来源:https://stackoverflow.com/questions/43646838/why-is-image-stored-different-than-the-one-imshowed