Matlab Contour Plot of 37380x2 array data points

I have an array of data points, where the first column are RMSD values and represent the x-axis and the second column are RoG values and represent the y-axis. I would like to make a contour plot of RoG (y-axis) vs RMSD (x-axis). I found and tried other code, but I need the color bar to represent the RMSD range instead of the data point density. The Code is shown below. The image shows my plot on the left, and I am trying to make a similar plot to the one on the right. The color bar gives the range of the RMSD values. The y-axis also only shows the minimum to maximum range. I don't need to change the color scheme.
ROGRMSDData is the attached array.
[N,Xedges,Yedges] = histcounts2(ROGRMSDData(:,1), ROGRMSDData(:,2), 50);
% or use [N,Xedges,Yedges] = histcounts2(X,Y,Xedges,Yedges);
% Compute bin centers
Xcnt = Xedges(2:end) - abs(diff(Xedges(1:2))/2);
Ycnt = Yedges(2:end) - abs(diff(Yedges(1:2))/2);
figure()
contourf(Xcnt,Ycnt, N)
% colorbar
cb = colorbar();

10 Comments

I'm confused. Or maybe you are.
To make a contour plot, you need to map three data elements:
  • position along the x-axis
  • position along the y-axis
  • "height" (which is represented by color, and by the contour lines)
You have told us that the first column of data is RMSD, and you want to map that to x.
You have told us that the second column of data is RoG, and you want to map that to y.
You have told us that you do NOT want to map binned data density as the height. (This makes sense to me.)
But ... and this is the part I am confused about ... what DO you want to map to the height?
That's actually where I'm confused too. In the plot on the right in the attached image, it looks like the height in their figure is RMSD. But can you have RMSD on the x-axis and let that be the height as well?
@the cyclist if I only have the RoG and RMSD data points, then it must be density of points that they used in the figure on the right. Their scale just seems like they used RMSD for the x-axis and the Z.
It is a strange fact that the scale of the colorbar in their figure is the same as the x-axis. But, it can't be that the height is simply equal to RMSD. (If it were, the color would be constant for a given RoG.)
Can you share the source of the figure you are trying to emulate?
@the cyclist Yes of course, https://doi.org/10.1016/j.str.2024.02.001
This looks like a free energy landscape plot (at least based on my web searches)..
I suspect you need to calculate the free energy using the radius of gyration and rmsd values.
@the cyclist @Cris LaPierre Yes, that is correct I needed to calculate that. I was able to do that and the output was in the form of a .h5 file which has the zValues. Apparently Matlab has an h5read command. Are you able to show me how to make that contour plot using that type of file? I've attached the RMSD values (x-axis), RoG values (y-axis), and the zValues file that has the free-energy values (z-axis). I opened the .h5 file in the HDFView program and saved only the zValues from the .h5 file into the zValues.txt file. Do I need to get rid of all the NaN cells? If you need the full .h5 file to try the h5read command instead, let me know. Thanks!
Ok, I got it figured out (mostly). I just used the h5read command and the .h5 file directly. The only issue now is Matlab doesn't fill the figure with yellow (zero) where most if the landscape is zero. I suspect that's because most of the zValues are NaN and not zero or close to zero.
xbins = h5read('landscape.h5', '/landscapes/name_1/xbins');
ybins = h5read('landscape.h5', '/landscapes/name_1/ybins');
zValues = h5read('landscape.h5', '/landscapes/name_1/zValues');
contourf(xbins, ybins, zValues);
hbar = colorbar;
ylabel(hbar,'kcal/mol');
"I suspect that's because most of the zValues are NaN"
If you want zeros instead of NaNs there:
zValues(isnan(zValues)) = 0;

Sign in to comment.

Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Asked:

on 4 Mar 2024

Commented:

on 6 Mar 2024

Community Treasure Hunt

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

Start Hunting!