Effacer les filtres
Effacer les filtres

How to cut out part of x axis in scatter plot ?

42 vues (au cours des 30 derniers jours)
Vikash Raj
Vikash Raj le 21 Fév 2023
Commenté : dpb le 28 Fév 2023
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;
ylabel('Latitude [Deg]','fontweight','bold','FontSize',12)
xlabel('Longitude [Deg]','fontweight','bold','FontSize',12)
title('$October$ $2016$','Interpreter','LaTex','FontSize',16)
  4 commentaires
Dyuman Joshi
Dyuman Joshi le 22 Fév 2023
The file is empty.
Vikash Raj
Vikash Raj le 22 Fév 2023
hi may be due to the slow network it might have happened. I have re -attached the data.

Connectez-vous pour commenter.

Réponse acceptée

dpb le 21 Fév 2023
Modifié(e) : dpb le 21 Fév 2023
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:
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
bW = 1×2
-2.6000 -468.0000
bE=polyfit(xE,[0 xE(2)],1) % and for E
bE = 1×2
-2.6000 468.0000
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])]
x = 1×12
-130.0000 -104.0000 -78.0000 -52.0000 -26.0000 0 0.0000 26.0000 52.0000 78.0000 104.0000 130.0000
which gives a continuous vector across the discontinuity.
You then use xticklabels to write the desired actual coordinates in place of the tick values.
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
xstr=cellstr(num2str(x(2,:).')); % tick label str for RH axes
  15 commentaires
Vikash Raj
Vikash Raj le 28 Fév 2023
Thanks alot. I have managed to plot the required graph using your suggestion.
dpb le 28 Fév 2023
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...

Connectez-vous pour commenter.

Plus de réponses (0)


En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by