How can I remove the white edge in the density map?

I used imagesc to plot a density map and plotted an additional point (the red one) in the figure to highlight that this is my basepoint. As seen in the image there is white edge at the x-axis of my density map, I probably think that there is no density points at that area. How can I turn this white edge to blue which is according to the colorbar 0 density.
I tried to extend the limit scale of 'ydata' before, this will result to a wrong density map, such that points below my basepoint are plotted.
testtri = worldpointscorrtri; % points i want to illustrate in density map
grid1 = 256; %refinement of map
minvalstri = min(testtri);
maxvalstri = max(testtri);
rangevalstri = maxvalstri - minvalstri;
xidxtri = 1 + round((testtri(:,1) - minvalstri(1)) ./ rangevalstri(1) * (grid1-1));
yidxtri = 1 + round((testtri(:,2) - minvalstri(2)) ./ rangevalstri(2) * (grid1-1));
densitytri = accumarray([yidxtri, xidxtri], 1, [grid1,grid1]); %note y is rows, x is col
densitytri = densitytri.*(1/max(densitytri,[], 'all'));
imagesc(densitytri, 'xdata', [minvalstri(1), maxvalstri(1)], 'ydata', [minvalstri(2), maxvalstri(2)]);
hold on;
plot(worldpoints_meltcorrtri(:, 1), worldpoints_meltcorrtri(:, 2), 'r*');
colorbar;
axis tight ;
axis square;
xlabel('x in mm ')
ylabel('-y in mm ')

2 comentarios

worldpointscorrtri??
Lightisthenight
Lightisthenight el 26 de Jun. de 2019
Editada: Lightisthenight el 26 de Jun. de 2019
this is just my image points, a 5000x3 matrix, I just corrected it in the question

Iniciar sesión para comentar.

 Respuesta aceptada

Adam Danz
Adam Danz el 26 de Jun. de 2019
Editada: Adam Danz el 26 de Jun. de 2019
Try this
axis tight
xlim([minvalstri(1), maxvalstri(1)])
ylim([minvalstri(2), maxvalstri(2)])
Note that these points are the centers of the corner squares so you'll cut off 1/2 of the upper, lower, right and left eges. Your resoltuion looks tiny so this won't be noticible but you might want to account for this issue by adding +/-1/2 of your square size to the axis limits.

4 comentarios

Thank you for your help. I got an error messge, saying that
Error using ylim (line 31)
Limits must be a 2-element vector of increasing numeric values.
Do you know how i can fix this issue, i still want my graph to go from 0 till -5 for example
Adam Danz
Adam Danz el 26 de Jun. de 2019
What are the values of [minvalstri(2), maxvalstri(2)] ? You're using them to set the image so if that's functional, this should work, too.
I got it. Thanks for your help
Adam Danz
Adam Danz el 26 de Jun. de 2019
Nice work!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 26 de Jun. de 2019

Comentada:

el 26 de Jun. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by