matplotlib - How to plot 2D matrix whose data is not equally spaced along x-axis using Python? -
I am trying to plot a 2d matrix using the matplotlib library (only one i know so far)
However, the function matplotlib.pyplot.imshow (matrix)
assumes that the data is evenly spaced with each axis, while the data I do not want to plot. My data looks like: The data on the first column line of the matrix is x = 0, the second column is on the data line x = instead of 1.27 x = 1, and x = 1.42 but not x = 2 is on the data line of the third column And so on
BTW, the data is equally distant with the y-axis
So I am thinking that anyway I can hope to plot it on anyway Am I Thanks for your time and kind support! In advance
------ in newb programming
Updates: First of all, thank you everyone for your suggestions! I have tried the methods and here are the output:
this This article has been employed by contourf
which I did not expect pcolormesh
does not give an ideal output either. The plot that I am trying to do is the data of seismic traces that represent the underground structure. I hope to plot something like this:
If there is any advice on how I can do this, please give me an indication! Thanks a lot!
I suggest you to use the function pcolormesh
.
You must enter the interval X, Y and 2D data defined in the 1D arrays accordingly. Below you are getting a simple example
import * x = logspace from pylab (log10 (1), log10 (100), 11) y = linspace (1,100,21) data = rand ( 20,10) Show pcolormesh (x, y, data) ()
Keep in mind that X and Y have an extra point in this case, data Fills the interval defined by X and Y. Otherwise, you can use the function
contourf
.
Cheers
Comments
Post a Comment