Question About Plotting Using Multiple Y-Axes in Same Plot

4 ビュー (過去 30 日間)
AmericanExpat26
AmericanExpat26 2017 年 12 月 14 日
コメント済み: James Barabas 2018 年 1 月 2 日
I am preparing a figure for a scientific publication that will use two y-axes. However, when trying to plot using yyaxis left and yyaxis right, it seems like yyaxis left the primary axis which goes on the plot first followed by what is specified by yyaxis right which is probably the secondary axis. When this happens, graphics targeting the right y-axis cover the more important graphics associated with the left y-axis. An example of what I talking about is attached.
The top plot in the example figure has pH on the left and salinity on the right which is the configuration I want, but the shaded area associated with salinity covers the profile of pH. The bottom figure has things reversed with salinity on the left and the other parameters on the right produces the effect I want with the profiles transposed on top of the shaded region associated with salinity. I tried putting yyaxis right ahead of yyaxis left in the script to try and change the order in which graphics are plotted, but it did not work. Is there any way in MATLAB to have the graphics associated with yyaxis right plot first and the graphics associated with yyaxis left plot second (as this would produce the desired configuration and effect I am looking for)? Thanks in advance for the help.

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 12 月 14 日
Perhaps something from the discussion https://blogs.mathworks.com/graphics/2014/11/04/sortmethod/ will help.
But if not, then change the z coordinates of one of the two portions. One way to do that would be to parent a hgtransform to the axes and parent all of the objects normally drawn in the axes into the hgtransform, and then set the transform matrix to move the z coordinates slightly below 0.
  1 件のコメント
James Barabas
James Barabas 2018 年 1 月 2 日
Yes, this should work. For example, if your original plot was created like this:
yyaxis left
plot(10:-1:1)
yyaxis right
area(1:10)
then you can add an hgtransform to the left side that moves graphics to higher z-values than the graphics on the right.
yyaxis left
zoffset = 1;
t = hgtransform('Matrix',makehgtform('translate',0,0,zoffset));
plot(t,10:-1:1)
yyaxis right
area(1:10)
set(gca,'SortMethod','depth')

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

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by