How to move this Y2 axis more to the right so it look better? Also how can I add lable Y1, Y2 like this?
plot1 = Plot[{ConditionalExpression[2 - x, x <= 1],
ConditionalExpression[x, x >= 1]}, {x, 0, 5},
Frame -> {True, True, True, False},
FrameStyle -> {Directive[Black, Thickness[0.003]],
Directive[Red, Thickness[0.003]], Automatic, Automatic},
PlotStyle -> Directive[Red, Thickness[0.01]], FrameLabel -> x];
plot2 = Plot[{x/(x + 1), 1 - x}, {x, 0, 5},
PlotRange -> {All, {0, 1}}, Frame -> {False, False, False, True},
FrameTicks -> {{None, All}, {None, None}},
FrameStyle -> {Automatic, Automatic, Automatic,
Directive[Blue, Thickness[0.003]]},
PlotStyle -> Directive[Blue, Thickness[0.01]]];
Overlay[{plot1, plot2}]
Using the method @mrtydn mentioned I got this.
How can I change the tick number and axis label to red and blue to match the axes's colors?
How to remove the white space between the gray background and the y axis here?
tickX = ({#1,
MaTeX[#1, "DisplayStyle" -> False, Magnification -> 2]} &) /@
Range[0, 5, 1];
tickY1 = ({#1,
MaTeX[#1, "DisplayStyle" -> False, Magnification -> 2]} &) /@
Range[0, 5, 1];
tickY2 = ({#1,
MaTeX[#1, "DisplayStyle" -> False, Magnification -> 2]} &) /@
Range[0, 1, 0.2];
background1 =
ListLinePlot[{{0, 1}, {1, 1}, {5, 5}}, Filling -> Top,
FillingStyle -> Opacity[0.75, LightGray]] /. _Line -> Sequence[];
plot1 = Show[background1,
Plot[{ConditionalExpression[2 - x, x <= 1],
ConditionalExpression[x, x >= 1]}, {x, 0, 5}
, PlotStyle -> Directive[Red, Thickness[0.01]]],
GridLines -> Automatic,
Frame -> {True, True, True, False},
FrameStyle -> {Directive[Black, Thickness[0.005]],
Directive[Red, Thickness[0.005]], Automatic, Automatic},
FrameLabel -> {MaTeX["\\mathrm{X}", Magnification -> 2],
MaTeX["\\mathrm{Y1}", Magnification -> 2], "",
MaTeX["\\mathrm{Y2}", Magnification -> 2]},
FrameTicks -> {{tickY1, tickY2}, {tickX, None}}
];
plot2 = Plot[{x/(x + 1), 1 - x}, {x, 0, 5},
PlotRange -> {All, {0, 1}}, Frame -> {True, True, True, False},
FrameStyle -> {Directive[Black, Thickness[0.005]],
Directive[Blue, Thickness[0.005]], Automatic, Automatic},
PlotStyle -> Directive[Blue, Thickness[0.01]],
FrameLabel -> {MaTeX["\\mathrm{X}", Magnification -> 2],
MaTeX["\\mathrm{Y2}", Magnification -> 2], "",
MaTeX["\\mathrm{Y2}", Magnification -> 2]},
FrameTicks -> {{tickY2, ""}, {tickX, None}}];
ResourceFunction["CombinePlots"][plot1, plot2, "AxesSides" -> "TwoY"]


ResourceFunction["CombinePlots"]there is alsoResourceFunction["MultipleAxesPlot"]– Bob Hanlon Aug 30 '22 at 16:41