TeX - LaTeX Asked on June 10, 2021
Despite multiple ordinates and axes discontinuities appearing adjacent in the pgfplots manual, achieving both in the same plot is proving difficult.
Specifically, I have the following pgfplots plot with two y-axes (see MWE below)
I would like to have an x-axis discontinuity that breaks the x-axis into 2 intervals: the first ranging from (-4,-3) and the second ranging from (0,4). I would like to retain the border to the graph in the style of the answer to this post, which has a discontinuity on the y-axis. I have tries updating it with no success and i’m not sure how to adapt the answer to a plot with double y-axes.
Any help is appreciated.
MWE
documentclass[tikz]{standalone}
usepackage{pgf,pgfplots}
pgfplotsset{compat=newest}
begin{document}
begin{tikzpicture}
pgfplotsset{set layers}
begin{axis}[scale only axis,
xlabel={$x$},
ylabel={Ordinate 1},
axis y line*=left,
xmin=-4.0, xmax=4.0
]
addplot[red] {x^2}; label{plot_one}
end{axis}
begin{axis}[scale only axis,
ylabel={Ordinate 2},
xmin=-4.0, xmax=4.0,
axis y line*=right,
axis x line=none,
]
addlegendimage{/pgfplots/refstyle=plot_one}addlegendentry{plot 1}
addplot[blue] {x}; label{plot_two}
addplot[green] {3*x}; label{plot_three}
addlegendentry{plot 2}
addlegendentry{plot 3}
end{axis}
end{tikzpicture}
end{document}
This is as far as I got. I tried using axis x discontinuity
but there is no way to place it into the right position. It wants to go to the right of 0, or to the left of xmax
if negative.
I also ran into some bugs regarding the axis environment and shifting. If you put the axis into a scope and shift the scope, the only thing moved is the legend. If you shift the axis, the bounding box is not shifted.
documentclass{standalone}
usepackage{pgf,pgfplots}
pgfplotsset{compat=newest}
begin{document}
begin{tikzpicture}
pgfplotsset{set layers}% ???
begin{axis}[scale only axis, width=1cm, height=4cm,
xlabel=vphantom{$x$},
ylabel={Ordinate 1},
axis y line*=left,
xmin=-4.0, xmax=-3.0,
ymin=0.0, ymax=16.0,
xtick={-4,-3}
]
addplot[red] {x^2}; label{plot_one}
coordinate (SE) at (rel axis cs: 1,0);
coordinate (NE) at (rel axis cs: 1,1);
end{axis}
begin{axis}[scale only axis, width=1cm, height=4cm,
xmin=-4.0, xmax=-3.0,
axis y line=none,
axis x line=none,
ymin=-12, ymax=12.0,
]
addplot[blue] {x};
addplot[green] {3*x};
end{axis}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
begin{axis}[xshift=2cm,
scale only axis, width=4cm, height=4cm,
xlabel={$x$},
axis y line=none,
xmin=0.0, xmax=4.0,
ymin=0.0, ymax=16.0,
name=right
]
addplot[red] {x^2}; label{plot_one}
coordinate (SW) at (rel axis cs: 0,0);
coordinate (NW) at (rel axis cs: 0,1);
end{axis}
begin{axis}[xshift=2cm,
scale only axis, width=4cm, height=4cm,
ylabel={Ordinate 2},
xmin=0.0, xmax=4.0,
axis y line*=right,
axis x line=none,
ymin=-12, ymax=12.0,
]
addlegendimage{/pgfplots/refstyle=plot_one}addlegendentry{plot 1}
addplot[blue] {x}; label{plot_two}
addplot[green] {3*x}; label{plot_three}
addlegendentry{plot 2}
addlegendentry{plot 3}
end{axis}
path (7cm,0);% kludge to fix bounding box
draw[red] (SE) -- (SW);
draw[red] (NE) -- (NW);
end{tikzpicture}
end{document}
Answered by John Kormylo on June 10, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP