Change the aspect ratio of x,y to plot Longitude and Latitude correctly ( I have the conversion needed- need help implementing it)

Hi there,
I am wanting to change my x,y axis to reflect true longitude and latitude scales.
The conversion is: 1 degree of longitude (x-axis) is equal to 111cos(latitude). Latitude being the Y-axis. I need this in order to create a single scalebar rather than 2 seperate ones.
this is the code I have but I do not know how to implement it - any help would be much appreciated!
Many thanks!
load('x_data.mat')
load('y_data.mat')
load('z_data.mat')
h = pcolor(X,Y, Z);
shading interp
%% map personalising
xlabel('Longitude (deg, E)');
ylabel('Latitude (deg, N)')
axis equal
% set axis limits
xlim([30.3 30.45])
ylim([40.7 40.8])
hold on

8 Comments

What does "111cos(latitude)" mean?
Do you want to set the DataAspectRatio of the axes?
Hi Jan,
I have visited the link you sent and I am still struggling.
so I am trying to set ratios as follows: for every degree of longitude (x-axis) - this is equal to 111*cos(y-axis (lattitude)) - I do not know how to specify this in the ratio (the y-axis or x-axis bit depending on how you formulate it). The Z-axis is simply /111(to get it into km) I believe .
Many Thanks
I do not understand "111*cos(y-axis (lattitude))". All I can imagine, is that "y-axis" is the Y-axis. Then this is a vector of different values. The cosine is not a linear function, and I do not see, how you want to use it to create "for every degree of longitude". I do not know also, how the Z-axis can be "/111".
I assume this is only a problem of the language. So please try to explain this with example data.
Hi Apologies in my poor explanation.
I have a data set of co-ordinates that I have had to plot as x and y instead of lat and lon. It looks fine but because I am needing a scale bar I now need both my x-axis and y-axis to be a true geographic representation so that I do not need two scale bars and only 1.
The map projections in matlab do not provide the resolution I need for topography and coastlines etc as my work is very small scale.
The reason I need to change the aspect ratio is because latitude changes differently to longitude with distance from the equator. At the equator this is fine, but as you move from the equator latitude and longitude no longervary the same. This is why I would like to set my aspect ratios for my axis.
There are 111km to every degree of latitude and there are 111cos(latitude value) that is equal to the longitude.
I have tried this function
as well as a few others and have not got it to work.
Does this make more sense? I am not sure if I am explaining it well.
Mnay thanks
You are welcome. This is a forum for solving problems in Matlab, so your questions are perfectly matching the purpose of this forum. :-)
Do you want to use the same scaling factor for the complete X and Y axes, or do you want to transform the data, such that the varying latitude is considered for all coordinates?
If you have tried some functions, please post the code and explain, what "not got it to work" explicitly means.
A small example of the inputs and the wanted output, e.g. drawn by hand, would be useful. Remember, that it does not matter for the actual problem, if the data are coordinates or stock prizes of bananas. The physical meaning of the values has no influence to the solution in Matlab, but it matters, in which format the inputs are stored.
Hi Jan,
Please see atched the result i am wanting to change ( the x and y axis to reflect geographic scales) .The image shows the result I have now so you get an idea of one of the types of plots I am making- as some of them are in 3D as below. Please also see attached example code so you understand what I have been doing. Axesm - I can't get to project properly and display all the ticks- I have just been trying this just in 2D and world map doesn't dispaly anything evewn if I use pcolorm. I will be using cellfun to plot data as well. I initially tried plottinmg onto a map that I couldn't get to work for eveything - This is why I wanted to see if I could change the aspect ratios myself. I have also tried xyz2ell.m from https://uk.mathworks.com/matlabcentral/fileexchange/15285-geodetic-toolbox?focused=6513492&tab=function but still not working.
Many Thanks
% I have read in aseries of X,Y,Z topographic data
h = pcolor(X,Y, Z); %shading the topography
shading interp;
% map personalising
xlabel('Longitude (deg, E)');
ylabel('Latitude (deg, N)')
demcmap([0 1000], 30 );
% I am now wanting to plot these co-ordinates for example in 3-D
x_dat = [29.2 29.6 29.4 29.8 29.5 29.6 29.7];
y_dat = [30.4 30.5 30.5 30.4 30.3 30.2 30.2];
z_dat = [10.2 12.1 11.5 7.6 8.9 10.2 11.5]/111; %km /deg
% as I am plotting in 3-D using scatter3 I don't believe yiu can use this
% with the geographic maps matlab produces.
%% other attempts I have made are:
%axesm('MapProjection','mercator','MapLatLimit',[40.7 40.8],'LabelUnits','degrees')
%axesm('MapLonLimit',[30.3 30.5],'LabelUnits','degrees','MapLatLimit',[40.7 40.8])
%worldmap([40.5 40.9],[30.3 30.5])
%[lat,lon,h]=xyz2ell(X,Y,Z)
@P_L: Please take into account, that I cannot read the code on your screen, if you do not post it here.
"Axesm - I can't get to project properly and display all the ticks- I have just been trying this just in 2D and world map doesn't dispaly anything evewn if I use pcolorm."
I cannot follow this description. Your code contains two calles of axesm, but they are commented - which one are you talkinh of.
"I will be using cellfun to plot data as well."
Why? Is this a part of the question?
"I initially tried plottinmg onto a map that I couldn't get to work for eveything"
Then please post the code and the error message, or a detailed description of the difference between your expectation and the results.
"Still not working" does not allow to give you any advice how to fix the code.
HI Jan,
problem solved. Thank you so much for trying to help.
I modified a function from
Many Thanks & all the best

Sign in to comment.

More Answers (0)

Categories

Asked:

P_L
on 12 Mar 2019

Commented:

P_L
on 13 Mar 2019

Community Treasure Hunt

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

Start Hunting!