modify XY axises of 2 graphs in one figure

2 Ansichten (letzte 30 Tage)
Minh Phuong Truong
Minh Phuong Truong am 10 Feb. 2022
Kommentiert: Ankit am 11 Feb. 2022
I have 2 graphs, which want to plot in same figure. The first one is matrix, use imagesc to display. The second data is coast.mat, I would like to overlap the coastline on my 1st graph.
How can I adjust, X axis 0-313 (from matrix data) equal to 112.9292-125.9792 (from coast.mat) , similar with Y axis 0-409 (matrix data) = 10.02083-27.02083 (coast.mat)
Thanks
  4 Kommentare
dpb
dpb am 10 Feb. 2022
@Ankit -- NB there is only one x-axes and the blue values are constrained to be only in the middle of the plot, not correlated of min-max ranges of the two to overlay the second on the first. And the two y axes are completely noncomparable in magnitudes...not what OP is looking for here.
Ankit
Ankit am 11 Feb. 2022
@dpb yes you are right... this will only plot two separate y axis...

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Minh Phuong Truong
Minh Phuong Truong am 11 Feb. 2022
graph1 = ncread('D:\addfea'); %read graph 1 nc file data
C = load('coasts.mat'); %load the coasts.mat file to get the coast line data
%display graph1 which the X axis min value = 0 equal to 112.9292 (from coasts.mat)
%X axis max value = 313 equal to -125.9792 (from coasts.mat)
%Northern hemisphere, grahp1 displays upside down
%Y axis min value = 0 equal to 27.02083 (from coasts.mat)
%Y axis max value = 409 equal to 10.02083 (from coasts.mat)
imagesc([112.9792 125.9792],[27.02083 10.02083],grahp1);
%display coast line
plot(C.Lon,C.Lat,'k');

Weitere Antworten (1)

dpb
dpb am 10 Feb. 2022
"How can I adjust, X axis 0-313 (from matrix data) equal to 112.9292-125.9792 (from coast.mat) , similar with Y axis 0-409 (matrix data) = 10.02083-27.02083 (coast.mat)"
Use linear interpolation would be one way...
>> interp1([0 313],[112.9292 -125.9792],[0:50:313 313])
ans =
112.9292 74.7649 36.6006 -1.5636 -39.7279 -77.8922 -116.0565 -125.9792
>>
would give you a new x-axis vector with which to label the image -- or, probably more appropriate to your case would be to reverse and turn the map coordinates into image dimensions.
Alternatively, you can use the x,y coordinates optional inputs into imagesc itself; there you may have to fudge a little because the center of the displayed corner pixels are on the range values; with 3-400 pixels the rounding may not be off enough to worry about. See the doc for imagesc for the syntax and example use.
  1 Kommentar
Adam Danz
Adam Danz am 10 Feb. 2022
The problem might be that OP wants to overlay linear data (imagesc) on top of geoaxes which are nonlinear. I've run into this problem myself in the past in this answer --> option 3.
But it's unclear how OP is plotting the coastal data so this is just a foggy hunch.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by