How to cut out part of x axis in scatter plot ?
44 次查看(过去 30 天)
显示 更早的评论
Hi,
I have have used scatter plots to plot Lattitude on x axis, Longitude on y axis and Absolute VTEC on Z axis.Typically my data is on both side of 180 deg. The longitudinal values are form -130 to -180 deg in West side while 180 to 130 deg in East side. When I plot the graph the longitudal values are displayed form -180 to 180 and my the graphs are seperated by showing large gaps in the x axis.
First I want to remove the part of this axis which dosent have graphs.
Secondly I wish bring the graph together at 180 deg and the x axis to be labled as
+130, .....+150 +160, +170, 180, -170 , -160, -150..........-130
Any suggestions will be highly appriciated.
Im attaching the codes that I used to obtain the graph.
mask = isfinite(Latitude) & isfinite(Longitude);
Latitude = Latitude(mask); Longitude = Longitude(mask);
N = 80;
[latbins, latedges] = discretize(Latitude, N);
[lonbins, lonedges] = discretize(Longitude, N+1);
denmat = accumarray([latbins(:), lonbins(:)], Absolute_VTEC(mask), [], @mean, NaN);
latmid = (latedges(1:end-1) + latedges(2:end))/2;
lonmid = (lonedges(1:end-1) + lonedges(2:end))/2;
h = pcolor(lonmid, latmid, denmat);
h.EdgeColor = 'none';
colorbar ()
colormap jet
ax = gca;
ax.LineWidth = 2;
ylim([-30 30]);
h = colorbar;
set(get(h,'label'),'string','VTEC');
ylabel('Latitude [Deg]','fontweight','bold','FontSize',12)
xlabel('Longitude [Deg]','fontweight','bold','FontSize',12)
title('$October$ $2016$','Interpreter','LaTex','FontSize',16)
采纳的回答
dpb
2023-2-21
编辑:dpb
2023-2-21
Unfortunately, MATLAB doesn't have the facility to create either split axes to show such a gap or to condense a section of an axes that doesn't contain data, nor to draw on an axes anything other than against the input x,y locations.
Those facilities would be nice to have, indeed, but for now you've got to work around it in one way or another.
There are two choices I see, first rescale the longitudinal data to be continuous--that's the following illustrative code:
FIRST METHOD
To create a representation such as you're looking for here on a single axes would require creating the x data to be continuous from [-130 +130] across +/-180.
Do this by linear mapping and joining the two subsections from [-180 -130] and [180 130]
xW=[-130 -180]; % west coordinate range
xE=[ 180 130]; % east coordinate range
bW=polyfit(xW,[xW(1) 0],1) % linear scaling coefficients for W coordinates
bE=polyfit(xE,[0 xE(2)],1) % and for E
NOTA BENE: the slope is same, just opposite sign of intercept so can set one from the other if desired rather than recompute.
So, now if given an input set of coordinates, to patch them together would be
x=[polyval(bW,[-130:-10:-180]) polyval(bE,[180:-10:130])]
which gives a continuous vector across the discontinuity.
You then use xticklabels to write the desired actual coordinates in place of the tick values.
SECOND METHOD
The alternate way to create the plot would be to use two independent axes drawn side by side -- this is doable, but tends to get complicated. Well, let's see what we can do here quickly...
hAx=axes; % make a default axes
posn=hAx.Position; % get the default position
hold on % don't destroy/change it
posn(3)=posn(3)/2; % set new width to one-half the default width
hAx(2)=axes('Position',posn+[posn(1)+posn(3)*2/3 0 0 0]); % make new offset by 2/3rds width
yticks(hAx(2),[]) % wipe out the second axes yticks so can see axis location
hAx(1).Position=posn; % now set the first width to half, too...
One sees you now do have to axes that look like they are one with the exception of the xlim both go from the default [0 1] range. Now you can plot the W and E portions of the data into the respective axes; (I've not tried, you may be able to ignore and clipping will take care of the other data at the RH limits of the two axes.)
When ready to plot set
hAx(2).YAxis.Visible='off'; % to hide the vertical line
so the extra y axis isn't visible. The 'box' property cannot be used here; if desired, will have to be drawn as xline, yline objects on the two axes or the opposite axis tick marks will show up again.
Then, for the tick labels, the last trick is
x=[-130:-25:-180; 180:-25:130]; % get the range of long's match the tick number
xstr=cellstr(num2str(x(1,:).')); xstr(end)={''}; % tick label str for LH axes
hAx(1).XTickLabel=xstr;
xstr=cellstr(num2str(x(2,:).')); % tick label str for RH axes
hAx(2).XTickLabel=xstr;
15 个评论
dpb
2023-2-28
Glad to have helped...if this has solved the original problem, why not go ahead and Accept the original Answer to let community know, if nothing else...
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!