4

I have a problem with the appearance of a mutli axis plot...

Currently I have the following: Current situation

However I do not want the arrow in the right y-axis but from the documentation I read that the * in the axis y line command should prevent this... but it doesn't. Further the upper axis, where the second x axis would appear, is now gray I however want it to be black. Hopefully someone knows the right commands to fix this.

\documentclass{standalone}                                                      
\usepackage{graphics,siunitx}                                                   
\usepackage{tikz,pgfplots}                                                      
\begin{document}
\begin{tikzpicture}                                                             
\pgfplotsset{%                                                                  
  compat=1.6,                                                                   
  width=10cm,                                                                   
  height=7cm,                                                                   
  scale only axis,                                                              
  every x tick label/.append style={font=\scriptsize\color{gray!80!black}},        
  xmajorgrids,                                                                  
  xminorgrids,                                                                  
  every y tick label/.append style={font=\scriptsize\color{gray!80!black}},     
  ymajorgrids,                                                                     
  yminorgrids                                                                   
}                                                                               

\begin{axis}[%                                                                  
xmin=0, xmax=40000,                                                             
xlabel={Time},                                                                  
ymin=-50, ymax=50,                                                              
ylabel={Power},                                                                 
axis y line*=left,                                                              
axis x line*=bottom]                                                            
\addplot [                                                                      
color=red,                                                                      
solid                                                                           
]                                                                               
coordinates{(0,0};                                                              
\label{pcharge}                                                                 
\addplot [                                                                      
color=green,                                                                    
solid                                                                           
]                                                                               
coordinates{(0,0)};                                                             
\label{pbattery}                                                                
\end{axis}                                                                      

\begin{axis}[%                                                                  
xmin=0, xmax=40000,                                                             
ymin=0, ymax=100,                                                               
ylabel={State of charge},                                                       
axis lines=left,                                                                
axis y line*=right,                                                             
axis x line=none,                                                               
legend style={at={(1.15,1)},anchor=north west,nodes=right}]                     

\addplot [                                                                      
color=blue,                                                                     
solid
]                                                                               
coordinates{(0,0)};                                                             
\addlegendentry{$SOC$};                                                         

\addlegendimage{/pgfplots/refstyle=pcharge}\addlegendentry{$P_\mathrm{charge}$};
\addlegendimage{/pgfplots/refstyle=pbattery}\addlegendentry{$P_\mathrm{battery}$};
\end{axis}                                                                      
\end{tikzpicture}
\end{document}
1
  • You may also want to consider \pgfplotsset{use layers} right after your \begin{tikzpicture}[..] statement(s) -- this improves multi-axis-plots. Jan 19 '13 at 11:13
5

This happens because you issued axis lines=left before axis y line*=right. If you remove axis lines=left, the arrow disappears. This looks like a bug, so you might want to file a bug report.

\documentclass[border=5mm]{standalone}                                                      
\usepackage{graphics,siunitx}                                                   
\usepackage{tikz,pgfplots}                                                      
\begin{document}
\begin{tikzpicture}                                                             
\pgfplotsset{%                                                                  
  compat=1.6,                                                                   
  width=10cm,                                                                   
  height=7cm,                                                                   
  scale only axis,                                                              
  every x tick label/.append style={font=\scriptsize\color{gray!80!black}},        
  xmajorgrids,                                                                  
  xminorgrids,                                                                  
  every y tick label/.append style={font=\scriptsize\color{gray!80!black}},     
  ymajorgrids,                                                                     
  yminorgrids                                                                   
}                                                                               

\begin{axis}[%                                                                  
xmin=0, xmax=40000,                                                             
xlabel={Time},                                                                  
ymin=-50, ymax=50,                                                              
ylabel={Power},                                                                 
axis y line*=left,                                                              
axis x line*=bottom]                                                            
\addplot [                                                                      
color=red,                                                                      
solid                                                                           
]                                                                               
coordinates{(0,0)};                                                              
\label{pcharge}                                                                 
\addplot [                                                                      
color=green,                                                                    
solid                                                                           
]                                                                               
coordinates{(0,0)};                                                             
\label{pbattery}                                                                
\end{axis}                                                                      

\begin{axis}[%                                                                  
xmin=0, xmax=40000,                                                             
ymin=0, ymax=100,                                                               
ylabel={State of charge},                                                                     
axis y line*=right,                                                             
axis x line=none,                                                               
legend style={at={(1.15,1)},anchor=north west,nodes=right}]                     
\addplot [                                                                      
color=blue,                                                                     
solid
]                                                                               
coordinates{(0,0)};                                                             
\addlegendentry{$SOC$};                                                         

\addlegendimage{/pgfplots/refstyle=pcharge}\addlegendentry{$P_\mathrm{charge}$};
\addlegendimage{/pgfplots/refstyle=pbattery}\addlegendentry{$P_\mathrm{battery}$};
\end{axis}                                                                      
\end{tikzpicture}
\end{document}
2
  • Thanks. Further any know how, how to make the top line to black? Normally when I use these settings for axis style a all the outer lines are black.
    – WG-
    Jan 18 '13 at 13:23
  • 1
    @WG-: That happens because you're setting axis x line*=bottom for both axes, which means the top line isn't drawn. If you remove the option from the first axis and set xmajorgrids=false for the second, it should work.
    – Jake
    Jan 18 '13 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.