-1

How does matplotlib ensure that a dataset can be within plot with specified size.

How do i from a plot stored as numpy, How do i read the color of the pixels illustration a datapoint (0,4) - in the plot.

example:

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")

First plot being :

enter image description here

Second plot being:

enter image description here

so the first has been resized to plot size 12,4 where the last basically plots the same data but just using the data shape as size... how do i change that?

Librosa just performs pcolormesh according to the GitHub source code

J.Down
  • 700
  • 1
  • 9
  • 32
  • are you plotting the 30x30 using ``plot`` or ``imshow`` or what? it is not clear to me what you are asking. Do you have some sample code? – Gerges May 17 '17 at 20:24
  • hopes it helps.. – J.Down May 17 '17 at 20:26
  • Well, not sure if I get the question, but I will give an answer. With ``pcolormesh``, you need to specify the x, y coordinates, as such: ``plt.pcolormesh(x,y,z)``. Each of x, y, z are 30x30 meshes. If in your code you only specify the color values as in ``plt.pcolormesh(z)``, then the x and y are automatically set to be a integer coordinates from 0 to 29. – Gerges May 17 '17 at 20:32
  • added an example. – J.Down May 17 '17 at 20:47
  • how do we know what figure-sizing parameters and plotting methods `librosa` used? – Paul H May 17 '17 at 20:49
  • You need to include a clear problem description. What would you like to achieve, what do you get and in how far does it not meet your expectations? – ImportanceOfBeingErnest May 18 '17 at 07:17

1 Answers1

0

You need to define another figure with its own size for the second figure.

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)

fig = plt.figure(figsize=(12,4))
plt.imshow(numpy_output_static, aspect = 'auto')
plt.show()
raw_input("asds")
Gerges
  • 6,269
  • 2
  • 22
  • 44
  • Yes... But if I stored this plot as a figure, how do i using the new defined figure extract datapoint row 0 column 0.. – J.Down May 18 '17 at 03:15