3

I have a Lat/Long vector, and another with Z values that I need to show on a 3d map just like the one on the right of the following figure. I tried bar3 but it's combuersome as it requires creating multiple graphs.

here's some code:

S4 = shaperead(filename)    
plot([S4.X],[S4.Y],'k'); % plots the map from a shapefile I loaded previously
XX = [-50 -51 ...];
YY = [-1 -2 ...];
ZZ = [ 2.2 3.2 ... ];
stem3(XX,YY,ZZ) % this is an option, but doesn't look good!! :(

Any ideas on how can I do this? thx!

enter image description here

Oliver Amundsen
  • 1,491
  • 2
  • 21
  • 40
  • Using the trick from here: http://stackoverflow.com/questions/28991376/how-to-set-x-and-y-values-when-using-bar3-in-matlab/28992462#28992462 you should be able to locate your bars in the positions you want. If you post some example data I might aswer it. – Ander Biguri Apr 09 '15 at 13:11
  • Thanks very much for the comment. That entry though seems to be on a gridded X,Y matrix? – Oliver Amundsen Apr 09 '15 at 13:37
  • Question: How are you plannig to plot the map? Can you show me a bit of code where I can start working from? some map you already know you want to use or something like that? Its hard to sitetise data for this example, especially because there is tons of approaches that you may not want to follow. – Ander Biguri Apr 09 '15 at 13:39
  • Looks promising. Can we have the actual shape? – Ander Biguri Apr 09 '15 at 13:54
  • 1
    Can't share the specific shapefile, but it's similar to any administrative_0 shapefile in here: http://www.diva-gis.org/gdata – Oliver Amundsen Apr 09 '15 at 13:56

1 Answers1

2

So based in the ability of relocating bar3 wherever you want here there is a simple code that does the job.

Things that does not and may be interesting for you:

1- Fill the map. 2.-Set the ligth 3.-Create the labels

2 and 3, they can be easily done. 1 I dont know.

Result:

enter image description here

CODE:

clear;clc;

S = shaperead('usastatehi.shp')
S(2)=[]; % Delete Alaska
S(10)=[];% Delete Haway
hold on
plot([S.X],[S.Y],'k'); % plots the map from a shapefile I loaded previously
% syntetic data
 Y=[40,45,25];
 X=[-100,-85,-80];
 Z=[0.5 2.3 1.4];

 cmap=colormap(strcat('parula(',num2str(length(Z)),')')); % Create a colormap. Change parula for anything you preffer

 ar=abs(diff(ylim))/abs(diff(xlim));
 for ii=1:length(X)
    h=bar3(Z(ii));
    Xaux=get(h,'Xdata');
    Xaux=Xaux-1+X(ii);
    set(h,'Xdata',Xaux)


    Yaux=get(h,'Ydata');
    Yaux=Yaux-1+Y(ii);
    set(h,'Ydata',Yaux)

    set(h,'FaceColor',cmap(ii,:));

 end
 axis off
Ander Biguri
  • 35,140
  • 11
  • 74
  • 120