# Keeping the same style inside a scaled plot

I have a graph with three different curves, two of which are very small compared to the other. I therefore decided to add a magnification of such curves inside my graph, in the following way:

\documentclass{scrbook}
\usepackage{classicthesis}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{semilogxaxis}[
xlabel={x},
ylabel={y},
xmin=1000, xmax=800000,
ymin=0, ymax=25,
enlargelimits,
width=.8\columnwidth,
every axis legend/.append style={nodes={right}},
cycle list name=black white]
coordinates{
(1846,     0.15)
(2304,     0.9)
(2846,     1.5)
};
coordinates{
(1846,     0.3)
(2304,     0.9)
(2846,     1.5)
};
coordinates{
(632,      19)
(916,      22)
(1764,     15)
(5106,     5)
(8146,     4)
(66026,    3)
(407900,   2.5)
(802932,   2)
};
\draw[black,dashed,thick] (axis cs:1500,-0.8) rectangle (axis cs:3500,2.2);
\coordinate (pt) at (axis cs:150000,11);
\legend{{Small curve \#1},{Small curve \#2},{Big curve}}
\end{semilogxaxis}
\node at (pt) {
\begin{tikzpicture}[baseline,trim axis left,trim axis right]
\begin{semilogxaxis}[
tiny,
xmin=1700, xmax=3000,
ymin=0, ymax=1.7,
enlargelimits,
%    cycle list name=black white,
/pgfplots/log ticks with fixed point,
/pgfplots/xtick={1700,2200,2700}]
coordinates{
(1846,     0.15)
(2304,     0.9)
(2846,     1.5)
};
coordinates{
(1846,     0.3)
(2304,     0.9)
(2846,     1.5)
};
\end{semilogxaxis}
\end{tikzpicture}};
\end{tikzpicture}

\end{document}


My question is: Is it possible to keep the same format in the magnified graph? I tried to specify it by hand, but it doesn't respect the filling. Specifying the cycle list name doesn't work, too.

In addition, but is not mandatory, I would appreciate a solution that avoid to specify the coordinates inside the magnified graph.

-

The tiny (and footnotesize) styles break the plot options because they call every mark/.append style={size=<value>}. If you use small (which doesn't use every mark) and set the width to a suitable value manually, it works fine.

I would recommend setting the axis line style=dashed for the inset plot to make it easier to connect the inset to the original area in the plot.

For avoiding to retype the coordinates, you should create a table using \pgfplotstableread{<your data>}{<\macroname} before your first plot. Then you can just say \addplot table {<\macroname} to plot the data.

Note that you don't need to use a node with a tikzpicture to place the inset, you can just provide the options at=(<coordinate>), anchor=center to get the same placement.

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{semilogxaxis}[
xlabel={x},
ylabel={y},
xmin=1000, xmax=800000,
ymin=0, ymax=25,
enlargelimits,
width=.8\columnwidth,
every axis legend/.append style={nodes={right}},
cycle list name=black white]
coordinates{
(1846,     0.15)
(2304,     0.9)
(2846,     1.5)
};
coordinates{
(1846,     0.3)
(2304,     0.9)
(2846,     1.5)
};
coordinates{
(632,      19)
(916,      22)
(1764,     15)
(5106,     5)
(8146,     4)
(66026,    3)
(407900,   2.5)
(802932,   2)
};
\draw[black,dashed,thick] (axis cs:1500,-0.8) rectangle (axis cs:3500,2.2);
\coordinate (pt) at (axis cs:150000,11);
\legend{{Small curve \#1},{Small curve \#2},{Big curve}}
\end{semilogxaxis}
\begin{semilogxaxis}[
at=(pt),anchor=center,
small, width=4.5cm,
xmin=1700, xmax=3000,
ymin=0, ymax=1.7,
enlargelimits,axis line style={dashed},
cycle list name=black white,
/pgfplots/log ticks with fixed point,
/pgfplots/xtick={1700,2200,2700}]
coordinates{
(1846,     0.15)
(2304,     0.9)
(2846,     1.5)
};
coordinates{
(1846,     0.3)
(2304,     0.9)
(2846,     1.5)
};
\end{semilogxaxis}
\end{tikzpicture}

\end{document}

-

Using the spy library is not ideal but definitely fun.

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{spy}
\begin{document}

\begin{tikzpicture}[spy using overlays={magnification=4, size=3cm, connect spies}]
\begin{semilogxaxis}[
xlabel={x},
ylabel={y},
xmin=1000, xmax=800000,
ymin=0, ymax=25,
enlargelimits,
width=.8\columnwidth,
every axis legend/.append style={nodes={right}},
cycle list name=black white]
\addplot coordinates{(1846,     0.15) (2304,     0.9) (2846,     1.5)};
\addplot coordinates{(1846,     0.3)  (2304,     0.9) (2846,     1.5)};
\addplot coordinates{(632,19) (916,22) (1764,15) (5106,5) (8146,4) (66026,3) (407900,2.5) (802932,2)};
\legend{{Small curve \#1},{Small curve \#2},{Big curve}}
\coordinate (handle) at (axis cs:2304,0.9);
\end{semilogxaxis}
\begin{semilogxaxis}[shift={(4cm,2cm)},scale=0.5,xmin=1700, xmax=3000,
ymin=0, ymax=1.7,
enlargelimits,]
\coordinate (a) at (axis cs:2304,0.9);
\spy [white] on (handle) in node at (a);
\end{semilogxaxis}
\end{tikzpicture}
\end{document}


In a nutshell, you define some coordinates in the big axis environment and then use spy in another axis environment. Using the axis coordinate system positioning seems working. You can improve further by using spy using outlines etc.

-
Thanks for the suggestion, probably also yours is a valid suggestion. Unfortunately, at the moment I don't have too much time to investigate it, but I'll give it a try in a second moment ;) – mp87 Apr 18 '12 at 18:19