Effacer les filtres
Effacer les filtres

Plotting a heat map with two variables with color dependent on third variable

8 vues (au cours des 30 derniers jours)
Chinwe Orie
Chinwe Orie le 2 Oct 2019
I have a matrix of x and y values, and I would like to plot them using a heat map. However, there is also a third column in the matrix of z-values, which I would like to determine the color of each point in the heat map. How would I do this?
  3 commentaires
Chinwe Orie
Chinwe Orie le 3 Oct 2019
Something like that yes, especially the checkered plot. That would be very ideal. My x and y are both 1xn vectors (n is something like 5000 for example). My z-variable is also a 1xn vector. However, the color input has to be a matrix. I'm not sure how I would use my z-variable to control color variation if the color input has to be a matrix.
Chinwe Orie
Chinwe Orie le 3 Oct 2019
%code
PC = [drops;heatfreqs;heatprom]; %drops, heatfreqs and heatprom are all 1x65550 vectors
PC = squeeze(PC);
pcolor(PC)
shading interp
colorbar
I've tried the above code, but all it gets me is a pcolor plot that doesn't take into account any of the values in the matrix. It just plots based on the coordinates of the matrix itself. I have attached a photo of what the graph looks like.

Connectez-vous pour commenter.

Réponses (1)

Poonam Mahapatra
Poonam Mahapatra le 13 Avr 2020
You can make a table of Xdata, Ydata and Cdata where Xdata is the variable having data to be displayed along the x-axis, Ydata is the variable having data to be displayed along the y-axis and Cdata is the variable having values to determine the color of each cell, using the following command:
>> tb1 = table(Xdata, Ydata, Cdata);
Then you can plot the heatmap using the following command:
>> h = heatmap(tb1,'Xdata','Ydata','ColorVariable','Cdata');
Please refer to the following documentation for more details:

Catégories

En savoir plus sur Geographic Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by