Multiple lines in one figure

8 次查看(过去 30 天)
Lise
Lise 2023-6-21
回答: Lise 2023-6-21
I'm plotting some data on top of a map, and I'm trying to add the Dutch Exclusive Economic Zone to the figure but it doesn't want to show.
figure('Color','w');
load NL_region_coast_RD.mat % contains x- and y-coordinates of the Dutch coastline (xRDc and yRDc)
line(xRDc/1000,yRDc/1000,'LineWidth',1.0,'Color','k');
hold on
line(rijksx/1000,rijksy/1000,'LineWidth',1.0,'Color','r'); % x- and y-coordinates of EEZ (rijksx and rijksy)
axis equal
xlim(rdxlim')
ylim(rdylim')
fsize=12;
set(gca,'FontSize',fsize);
set(gca,'YAxisLocation','left')
After this piece of code, I use imagesc to layer my data on top of it (as a colormap). This works on top of the Dutch coastline, but the EEZ just won't show. Does anyone know why, and how to fix it?
  3 个评论
Lise
Lise 2023-6-21
I am afraid that the files I'm using are private... I'm writing my bachelor's thesis at the moment, and the files have been provided by my supervisor. To run this code, 4 different files are required and I can't share them. However, I know that said code and data works as it should. They are simply two arrays, one for x-coordinates and one for y-coordinates (both 39551x1 doubles). This is the entire code I wrote myself, and below is the result.
load NL_region_coast_RD.mat
bplot=10; % additional zone beyond area covered by stations
rdxlim=[-210 350]; % [km]
rdylim=[300 1100];
% loading EEZ data
filen='NL_Exclusive_Economic_Zone__EEZ__may2023.csv';
fid=fopen(filen,'r');
D=textscan(fid,'%s%f%f%f%d%s%s%f%f%f%f%f%f', 'delimiter',',', 'Headerlines',1);
fclose(fid);
xdeg=D{1};
xdeg=str2double(xdeg);
xmin=D{2};
xsec=D{3};
ydeg=D{4};
ymin=D{5};
ymin=double(ymin);
ysec=D{6};
ysec=str2double(ysec);
EEZlen=length(xdeg);
rijksx=zeros(EEZlen,1);
rijksy=zeros(EEZlen,1);
% converting EEZ data: dms --> decimal deg --> rijksdriehoek
xcor=xdeg+(xmin/60)+(xsec/3600);
ycor=ydeg+(ymin/60)+(ysec/3600);
for i=1:EEZlen
[EEZx,EEZy]=wgs2rd(xcor(i),ycor(i));
rijksx(i)=EEZx/1000;
rijksy(i)=EEZy/1000;
end
% plotting country borders
figure('Color','w');
line(xRDc/1000,yRDc/1000,'LineWidth',1.0,'Color','k');
hold on
line(rijksx/1000,rijksy/1000,'LineWidth',1.0,'Color','r');
% axes handling
axis equal
xlim(rdxlim')
ylim(rdylim')
fsize=12;
set(gca,'FontSize',fsize);
set(gca,'YAxisLocation','left')
Simon Chan
Simon Chan 2023-6-21
Is there any possibility that the values of the variables rijksx/1000 and rijksy/1000 is outside the axis limit? Noticed that you already divide EEZx and EEZy in the for loop by 1000 already.

请先登录,再进行评论。

回答(2 个)

Joe Vinciguerra
Joe Vinciguerra 2023-6-21
The is nothing innately wrong with your code.
Check that the values within rdxlim and rdylim are appropriate for the dataset.
If you can, move imagesc before the lines so it layers the lines on top. If you can't relocate imagesc in your code:
Or change the plotting order like this:
figure("Color", "w")
line([0:1:10], [0:1:10],'LineWidth',1.0,'Color','k');
hold on
line([0:1:10], [0:10:100],'LineWidth',1.0,'Color','r');
imagesc
g=get(gca,'Children');
g=g([3 2 1]);
set(gca,'children',g);
  2 个评论
Lise
Lise 2023-6-21
I have set the opacity of the imagesc to 0.5, and the coastlines are visible on top. The issue is that the part:
line(rijksx/1000,rijksy/1000,'LineWidth',1.0,'Color','r');
does not show at all, any way I seem to try. I have tried changing the order, plotting the coast lines over the imagesc and it works, but the EEZ still does not show.
Joe Vinciguerra
Joe Vinciguerra 2023-6-21
It's there. It's just outside of your limits. And I would guess that it's not scaled correctly. Here is a screenshot of the figure file you provided, zoomed in on the region where your missing data can be found:

请先登录,再进行评论。


Lise
Lise 2023-6-21
I figured it out. I switched latitude and longitude, and the data was rotated 90 degrees, so I used rot90 to fix it. It works now! Thanks for the help

类别

Help CenterFile Exchange 中查找有关 Visual Exploration 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by