How do I create a 2D plot which looks something like a matrix plot with an array of values in the horizontal axis (x) and multiple arrays of values in the vertical axis (y)?

Following are my data values:
x =[0,0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]
y1=[0.02,0.02,0.02,0.01,0,0,0,0,0,0,0,0]
y2=[0,0.01,0.03,0.05,0.26,0.56,0.9,1,1,1,1,1]
y3=[0.02,0.03,0.17,0.72,1,1,1,1,1,1,1,1]
y4=[0.02,0.07,0.35,0.96,1,1,1,1,1,1,1,1]
y5=[0.02,0.23,0.71,1,1,1,1,1,1,1,1,1]
y6=[0.03,0.23,0.9,1,1,1,1,1,1,1,1,1]
y7=[0.03,0.45,0.99,1,1,1,1,1,1,1,1,1]
y8=[0,0.54,1,1,1,1,1,1,1,1,1,1]
y9=[0.03,0.76,1,1,1,1,1,1,1,1,1,1]
y10=[0.01,0.79,1,1,1,1,1,1,1,1,1,1]
I tried to first create a scatter plot with smooth lines but it does not seem to be the best way to visualize the data as repeated values like 1 overlap. Therefore I want to create a 2D matrix plot where all the values of y will be in shades of black and white, where white color would be assigned to data value 1 and black to data value 0 and all the other y values will have the intermediate shades. I am not sure how to do this in MATLAB. I tried to create these plots in Excel, IDL, Mathematica but I did not get what I am looking for. Kindly suggest if there is a way to create these plots.

1 Comment

Image Analyst, the image below the text is what I get after running the additional code which you suggested. The 'grid on' function looks good. However, the x axis ticks do not match with my actual data values in the x array. Is it not possible to match the ticks just as it is with the x array data values from 0 to 1. I can imagine because of 0.05 as one of the data values in the x array the increment is not equally spaced but is there a way to keep all the data values in the x axis as it is. I have created the image on the top of the text by manually adding shades in excel cells with labels, not a very efficient way but still this is what I am trying to achieve via MATLAB or any other software. It seems I need to do a lot of editing in the Graphics editor window to get to the excel based visualization. Do you know if it is possible to emulate the excel based visualization in MATLAB without much manual edits?

Sign in to comment.

Answers (2)

What about making it an image:
x =[0,0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]
y1=[0.02,0.02,0.02,0.01,0,0,0,0,0,0,0,0]
y2=[0,0.01,0.03,0.05,0.26,0.56,0.9,1,1,1,1,1]
y3=[0.02,0.03,0.17,0.72,1,1,1,1,1,1,1,1]
y4=[0.02,0.07,0.35,0.96,1,1,1,1,1,1,1,1]
y5=[0.02,0.23,0.71,1,1,1,1,1,1,1,1,1]
y6=[0.03,0.23,0.9,1,1,1,1,1,1,1,1,1]
y7=[0.03,0.45,0.99,1,1,1,1,1,1,1,1,1]
y8=[0,0.54,1,1,1,1,1,1,1,1,1,1]
y9=[0.03,0.76,1,1,1,1,1,1,1,1,1,1]
y10=[0.01,0.79,1,1,1,1,1,1,1,1,1,1]
theImage = [y1;y2;y3;y4;y5;y6;y7;y8;y9;y10]
imshow(theImage, [], 'InitialMagnification', 1600);
colorbar;

8 Comments

Thanks a lot Analyst for your helpful answer. The second answer is very much like what I have been thinking. Is there any way to show all the grids clearly? I mean now with the white portion of the plot it is hard to differentiate among individual boxes or values which essentially have data value 1. And if I can find an easy way to label the x and y axis it would be perfect along with a legend? But it seems the x axis was not considered while plotting the image? I tried it using MATLAB and the Image plot opens in a new Graphics window which has many options. I will try to figure it out if there is a way to manually label the x and y axis and add a legend. If I could directly do it via the code, it would make my task easier because I have to create many such plots. This is only 1 example. I can imagine to create the labels and legends for 1 or two examples but it would be handy if I can create the code once so that from next time I only replace the x and y data values and the plots are generated without the need for manual editing on each and every plot.
In any case I appreciate your help, Image Analyst.
Well you could add this:
ax = gca;
ax.XTick = 0.5:10.5;
ax.YTick = 0.5:10.5;
grid on;
axis on;
I added the following lines in the code set(gca,'XTickLabel',['0';'0.05';'0.1';'0.2';'0.3';'0.4';'0.5';'0.6';'0.7';'0.8';'0.9';'1']) set(gca,'YTickLabel',['y1';'y2';'y3';'y4';'y5';'y6';'y7';'y8';'y9';'y10']) but I get an error message, 'Dimensions of matrices being concatenated are not consistent'. There are so many links and syntaxes in MATLAB that I am getting lost. Moreover, I see that that I need to manually uncheck the 'reverse' option on y axis every time the image is generated. This seems to be taking too much time than I expected. Kindly help. I am new to MATLAB.
What are you trying to do anyway? It looks like you could just plot this much nicer using bar().
I guess my question was not clear enough. I have attached two plots which show the differences. The plot on the top was made with the same data using Excel 'Scatter with smooth lines' option and the second plot was made like I mentioned in my earlier comment. The first plot is not able to show the overall results because the y data values with 1 are overlapping with each other, i.e., the lines are on top of each other. Whereas in the second excel plot with manual edits all the values are displayed as color shades. These data values represent just one scenario. Likewise, I have many other scenarios where I need to plot them so that the differences between two scenarios are clear enough. With a 'Scatter plot with smooth lines' in excel the differences don't show up. If you have a better idea, you are most welcome to share. I have no clue what the bar() option is. I have to look it up.
Do you mean a bar chart? Or a Column Chart as it is known in Excel? I guess even with this option the differences are not clear enough? But I am not sure if you mean this?
Let me put the question in another way. Which will be the best visualization/plot option to show the differences between the 2 SCENARIOS A & B graphically ? Please check attached image.

Sign in to comment.

where each value is represented by a patch of that color or gray level. Or else use plot() or scatter() and then use paint or Photoshop or some photo editing package to mock up what you'd like to see, because I'm not visualizing what it might be.

Categories

Asked:

on 26 Dec 2015

Edited:

on 27 Dec 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!