Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
You may also want to consider \pgfplotsset{use layers} right after your \begin{tikzpicture}[..] statement(s) -- this improves multi-axis-plots. –  Christian Feuersänger Jan 19 '13 at 11:13
add comment

1 Answer

up vote 5 down vote accepted

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}
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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