Multiple axes: how to plot the correct scale on both x-axes and y-axes?

2 ビュー (過去 30 日間)
giutri
giutri 2019 年 7 月 18 日
コメント済み: Adam Danz 2019 年 7 月 23 日
Hello,
CAn I ask you some advice for these two problems? I am using Matlab very ofte.. Apologies for any mistakes.
I am using a variogramfit to run a semivariogram analysis of three datasets (they different in length and magnitude). I would plot the result in one graph with two y-axes and 2 x-axes. I was able to use the instructions for multiple axes but I realised that I got some weird result. On the second y-axes and x-axes I have got double ticks that possibly reflect two different scale? I am not sure how I can proceed. Any suggestions?
I would select three different colour for each datasets, but I am not sure how to do it. I have tried to change the color after plotting, but it is not possible.
figure(1)
[a1,c1,n1] = variogramfit(dist_uv_F,gamma_uv_F,a01_F,c01_F,[],...
'solver','fminsearchbnd',...
'nugget',0,...
'plotit',true)
hold on
[a1,c1,n1] = variogramfit(dist_uvV,gamma_uvV,a01_V,c01_V,[],...
'solver','fminsearchbnd',...
'nugget',0,...
'plotit',true)
hold on
ylabel('gamma (uv)')
xlabel('lag distance dataset1-2')
hold on
ax1 = gca;
set(ax1, 'XColor','k', 'YColor','k')
ax2 = axes('Position', get(ax1,'Position'),...
'XAxisLocation', 'top',...
'YAxisLocation', 'right',...
'Color','none',...
'XColor', 'k', 'YColor', 'k');
hold on
h = variogramfit(dist_uv,gamma_uv,a01,c01,[],...
'solver','fminsearchbnd',...
'nugget',0,...
'plotit',true)
hold on
xlabel('lag distance dataset3')

採用された回答

Adam Danz
Adam Danz 2019 年 7 月 18 日
編集済み: Adam Danz 2019 年 7 月 19 日
The double ticks are due to the axis 'Box" property set to 'on' and the misalignment of ticks between the upper and lower axes (or left and right axes). There are two ways around this.
1) If you want the keep the 'box' 'on', scale the pair of axes (upper / lower or left /right) so they have the same number of ticks at equal spacing.
  • use xlim() or ylim() to set the axis limits
  • use set(h, 'xtick', ...) or set(h, 'ytick',...) to set the ticks
2) Turn off the axis box for both axes
  • box(ax1,'off')
  • box(ax2,'off')
Turning the grid on for both axes may help visualize the problem.
  • grid(ax1,'on')
  • grid(ax2,'on')
  2 件のコメント
giutri
giutri 2019 年 7 月 23 日
Thanks! Now it worked!
Can I also ask some suggestions to modify the markers in the script? I would have different markers for different dataset but unfortunately I am not able to modify them after the plot.
Adam Danz
Adam Danz 2019 年 7 月 23 日
I'm not familiar with the 3rd party function "variogramfit". To plot with different markers, you could use gscatter() or you could plot the groups individually.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeVisual Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by