Draw different curves with different scales on TikZ
up vote
5
down vote
favorite
The following code
begin{tikzpicture}[scale=0.9]
begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.95,0.95)}}]
addlegendimage{empty legend}
addlegendentry{Metrics}
addplot+[smooth]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
addplot+[smooth]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
(7,21.34288)};
addlegendentry{b}
end{axis}
end{tikzpicture}
produces the picture:
As we can see, the curves are very different in magnitude and so the trend of red curve seems to be constant. How can I draw these two curves with different scales?
tikz-pgf
add a comment |
up vote
5
down vote
favorite
The following code
begin{tikzpicture}[scale=0.9]
begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.95,0.95)}}]
addlegendimage{empty legend}
addlegendentry{Metrics}
addplot+[smooth]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
addplot+[smooth]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
(7,21.34288)};
addlegendentry{b}
end{axis}
end{tikzpicture}
produces the picture:
As we can see, the curves are very different in magnitude and so the trend of red curve seems to be constant. How can I draw these two curves with different scales?
tikz-pgf
2
This is what logarithmic plots are for.
– marmot
17 hours ago
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
The following code
begin{tikzpicture}[scale=0.9]
begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.95,0.95)}}]
addlegendimage{empty legend}
addlegendentry{Metrics}
addplot+[smooth]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
addplot+[smooth]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
(7,21.34288)};
addlegendentry{b}
end{axis}
end{tikzpicture}
produces the picture:
As we can see, the curves are very different in magnitude and so the trend of red curve seems to be constant. How can I draw these two curves with different scales?
tikz-pgf
The following code
begin{tikzpicture}[scale=0.9]
begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.95,0.95)}}]
addlegendimage{empty legend}
addlegendentry{Metrics}
addplot+[smooth]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
addplot+[smooth]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
(7,21.34288)};
addlegendentry{b}
end{axis}
end{tikzpicture}
produces the picture:
As we can see, the curves are very different in magnitude and so the trend of red curve seems to be constant. How can I draw these two curves with different scales?
tikz-pgf
tikz-pgf
asked 17 hours ago
Mark
1956
1956
2
This is what logarithmic plots are for.
– marmot
17 hours ago
add a comment |
2
This is what logarithmic plots are for.
– marmot
17 hours ago
2
2
This is what logarithmic plots are for.
– marmot
17 hours ago
This is what logarithmic plots are for.
– marmot
17 hours ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
This is not a complete answer. The following code just demonstrates how you can plot graphs in two different axes.
documentclass[border=3mm]{standalone}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}[scale=0.9]
pgfplotsset{every axis legend/.style={
anchor= west,
draw=none,}
}
begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,
y tick label style={blue},
legend style= {at={(0.78,0.55)}},
]
addplot[smooth,mark=*,blue]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
end{axis}
begin{axis}[name=plot2, axis y line*=right, axis x line=none,
xlabel=clusters ,colormap/blackwhite,
y tick label style={red},
legend style= {at={(0.78,0.45)}},
]
addplot[smooth,mark=square*,red]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487) (7,21.34288)};
addlegendentry{b}
end{axis}
end{tikzpicture}
end{document}
add a comment |
up vote
5
down vote
You could use a semilogyaxis
.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=0.9]
begin{semilogyaxis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.95,0.6)}}]
addlegendimage{empty legend}
addlegendentry{Metrics}
addplot+[smooth]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
addplot+[smooth]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
(7,21.34288)};
addlegendentry{b}
end{semilogyaxis}
end{tikzpicture}
end{document}
Is there a recommendation to use ssemilogaxis
instead ofaxis
withymode=log
option ? Or are these two syntaxes equivalent ?
– BambOo
17 hours ago
@BambOo They are equivalent, see p. 41 of the pgfplots manual.
– marmot
17 hours ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
This is not a complete answer. The following code just demonstrates how you can plot graphs in two different axes.
documentclass[border=3mm]{standalone}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}[scale=0.9]
pgfplotsset{every axis legend/.style={
anchor= west,
draw=none,}
}
begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,
y tick label style={blue},
legend style= {at={(0.78,0.55)}},
]
addplot[smooth,mark=*,blue]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
end{axis}
begin{axis}[name=plot2, axis y line*=right, axis x line=none,
xlabel=clusters ,colormap/blackwhite,
y tick label style={red},
legend style= {at={(0.78,0.45)}},
]
addplot[smooth,mark=square*,red]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487) (7,21.34288)};
addlegendentry{b}
end{axis}
end{tikzpicture}
end{document}
add a comment |
up vote
4
down vote
accepted
This is not a complete answer. The following code just demonstrates how you can plot graphs in two different axes.
documentclass[border=3mm]{standalone}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}[scale=0.9]
pgfplotsset{every axis legend/.style={
anchor= west,
draw=none,}
}
begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,
y tick label style={blue},
legend style= {at={(0.78,0.55)}},
]
addplot[smooth,mark=*,blue]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
end{axis}
begin{axis}[name=plot2, axis y line*=right, axis x line=none,
xlabel=clusters ,colormap/blackwhite,
y tick label style={red},
legend style= {at={(0.78,0.45)}},
]
addplot[smooth,mark=square*,red]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487) (7,21.34288)};
addlegendentry{b}
end{axis}
end{tikzpicture}
end{document}
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
This is not a complete answer. The following code just demonstrates how you can plot graphs in two different axes.
documentclass[border=3mm]{standalone}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}[scale=0.9]
pgfplotsset{every axis legend/.style={
anchor= west,
draw=none,}
}
begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,
y tick label style={blue},
legend style= {at={(0.78,0.55)}},
]
addplot[smooth,mark=*,blue]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
end{axis}
begin{axis}[name=plot2, axis y line*=right, axis x line=none,
xlabel=clusters ,colormap/blackwhite,
y tick label style={red},
legend style= {at={(0.78,0.45)}},
]
addplot[smooth,mark=square*,red]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487) (7,21.34288)};
addlegendentry{b}
end{axis}
end{tikzpicture}
end{document}
This is not a complete answer. The following code just demonstrates how you can plot graphs in two different axes.
documentclass[border=3mm]{standalone}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}[scale=0.9]
pgfplotsset{every axis legend/.style={
anchor= west,
draw=none,}
}
begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,
y tick label style={blue},
legend style= {at={(0.78,0.55)}},
]
addplot[smooth,mark=*,blue]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
end{axis}
begin{axis}[name=plot2, axis y line*=right, axis x line=none,
xlabel=clusters ,colormap/blackwhite,
y tick label style={red},
legend style= {at={(0.78,0.45)}},
]
addplot[smooth,mark=square*,red]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487) (7,21.34288)};
addlegendentry{b}
end{axis}
end{tikzpicture}
end{document}
edited 13 hours ago
answered 17 hours ago
nidhin
2,889926
2,889926
add a comment |
add a comment |
up vote
5
down vote
You could use a semilogyaxis
.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=0.9]
begin{semilogyaxis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.95,0.6)}}]
addlegendimage{empty legend}
addlegendentry{Metrics}
addplot+[smooth]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
addplot+[smooth]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
(7,21.34288)};
addlegendentry{b}
end{semilogyaxis}
end{tikzpicture}
end{document}
Is there a recommendation to use ssemilogaxis
instead ofaxis
withymode=log
option ? Or are these two syntaxes equivalent ?
– BambOo
17 hours ago
@BambOo They are equivalent, see p. 41 of the pgfplots manual.
– marmot
17 hours ago
add a comment |
up vote
5
down vote
You could use a semilogyaxis
.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=0.9]
begin{semilogyaxis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.95,0.6)}}]
addlegendimage{empty legend}
addlegendentry{Metrics}
addplot+[smooth]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
addplot+[smooth]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
(7,21.34288)};
addlegendentry{b}
end{semilogyaxis}
end{tikzpicture}
end{document}
Is there a recommendation to use ssemilogaxis
instead ofaxis
withymode=log
option ? Or are these two syntaxes equivalent ?
– BambOo
17 hours ago
@BambOo They are equivalent, see p. 41 of the pgfplots manual.
– marmot
17 hours ago
add a comment |
up vote
5
down vote
up vote
5
down vote
You could use a semilogyaxis
.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=0.9]
begin{semilogyaxis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.95,0.6)}}]
addlegendimage{empty legend}
addlegendentry{Metrics}
addplot+[smooth]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
addplot+[smooth]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
(7,21.34288)};
addlegendentry{b}
end{semilogyaxis}
end{tikzpicture}
end{document}
You could use a semilogyaxis
.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}[scale=0.9]
begin{semilogyaxis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.95,0.6)}}]
addlegendimage{empty legend}
addlegendentry{Metrics}
addplot+[smooth]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
addlegendentry{a}
addplot+[smooth]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
(7,21.34288)};
addlegendentry{b}
end{semilogyaxis}
end{tikzpicture}
end{document}
answered 17 hours ago
marmot
82.3k493176
82.3k493176
Is there a recommendation to use ssemilogaxis
instead ofaxis
withymode=log
option ? Or are these two syntaxes equivalent ?
– BambOo
17 hours ago
@BambOo They are equivalent, see p. 41 of the pgfplots manual.
– marmot
17 hours ago
add a comment |
Is there a recommendation to use ssemilogaxis
instead ofaxis
withymode=log
option ? Or are these two syntaxes equivalent ?
– BambOo
17 hours ago
@BambOo They are equivalent, see p. 41 of the pgfplots manual.
– marmot
17 hours ago
Is there a recommendation to use s
semilogaxis
instead of axis
with ymode=log
option ? Or are these two syntaxes equivalent ?– BambOo
17 hours ago
Is there a recommendation to use s
semilogaxis
instead of axis
with ymode=log
option ? Or are these two syntaxes equivalent ?– BambOo
17 hours ago
@BambOo They are equivalent, see p. 41 of the pgfplots manual.
– marmot
17 hours ago
@BambOo They are equivalent, see p. 41 of the pgfplots manual.
– marmot
17 hours ago
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464271%2fdraw-different-curves-with-different-scales-on-tikz%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
This is what logarithmic plots are for.
– marmot
17 hours ago