Gapless 2d color plot
4 views (last 30 days)
Show older comments
Hello everyone,
I want to plot the following data:
X,Y and Z, where X and Y are a vector of equal length/size and Z is a matrix with the dimension of X*Y. Z shall be displayed as a color. I know I can use imagesc()and pcolor() to plot. However, I have the following problem.
imagesc() does not place the pixels as I want them. The range for the x-values goes from 0.0 to 0.5. The X axis is binned/divided into 50 parts, means it goes from 0.0 to 0.001, 0.002 and so on. The first pixel is not located perfectly from 0.0 to 0.001.
The problem with pcolor() would be, that the x and y values are always 1,2,3,4,5 and so on. It is not possible to red X,Y,Z in, at least not for me. If I would be able to place the pixels as perfect as in pcolor() that would be actually my solution.
In the following you see the result for the imagesc(). From 0.0 to 0.05 there should be exactly 5 pixels, and the edge of the last one should exactly end at the tick marker of 0.05. It is not like that, however. I have used the search function a lot, I was not able to find proper solutions of how I could define the center and/or width of the pixels. And why does imagesc() display the last value in x direction twice??? I mean, for y and y axis the last value/pixel is much bigger than the others, why??? The problem is not how to plot my data, but rather how to plot them in an appropriate and "clean" way. I would be very helpful if someone can give me an answer finally! Thanks in advance to all of you!
0 Comments
Answers (1)
Steven Lord
on 21 Mar 2020
The problem with pcolor() would be, that the x and y values are always 1,2,3,4,5 and so on.
That's because you called pcolor with one input. If you call it with three inputs, according to the documentation "pcolor(X,Y,C) specifies the x- and y-coordinates for the vertices. The size of C must match the size of the x-y coordinate grid. For example, if X and Y define an m-by-n grid, then C must be an m-by-n matrix."
Alternately the heatmap or histogram2 functions may be of use to you. histogram2 has a syntax where you specify the XBinEdges, YBinEdges, and BinCounts rather than the raw data to be binned.
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!