Azzera filtri
Azzera filtri

Question About Plotting Using Multiple Y-Axes in Same Plot

2 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Walter Roberson
Walter Roberson il 14 Dic 2017
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 Commento
James Barabas
James Barabas il 2 Gen 2018
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')

Accedi per commentare.

Categorie

Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by