2

I have a code that draws two x axis and one y axis. However, I cant control the upper x axis ticks.

\documentclass[12pt,twoside, a4paper]{report}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}  
 \usepackage{tikz} 
 \usepackage{pgfplots}
\pgfplotsset{compat=1.6}
\begin{document}


\begin{tikzpicture}
\begin{axis}[filter discard warning=false,scale only axis,
  width=7.41cm,
  height=4.415cm, 
  xmin=1,xmax=9,
  ymin=0.01,ymax=100, 
  axis x line*=bottom,
  xtick = {1,2,3,4,5,6,7,8,9},
  xticklabels = {0.15, 0.25, 0.3, 0.4, 0.5, 0.8, 1.0, 1.2, 1.6},
  enlargelimits=false,axis on top=true,
  xlabel=lower x, ylabel=left y]
 \addplot[color=red,mark=x] coordinates {
 (1, 0.1) (2, 10) (3,30) (4, 45) (5, 60) (6, 72) (7, 81) (8, 80) (9,83) (10, 85)};
 \end{axis}

 \begin{axis}[filter discard warning=false,scale only axis,
   width=7.41cm,
   height=4.415cm, 
   xmin=1, xmax=9,
   xtick = {1,3,5,7,9},
   xticklabels = {1,3,5,7,9},
   axis x line*=top,
   axis y line=none,
   enlargelimits=false,axis on top=true,
   xlabel=upper x]
   \end{axis}
  \end{tikzpicture}
  \end{document}

In second x axis, I want to divide ticks into {1,3,5,7,9} but it starts with 3. Can you please help me? enter image description here

Torbjørn T.
  • 206,688
user3104352
  • 323
  • 2
  • 11

1 Answers1

2

The problem is caused from the different (non) y-scaling.

Add the same ymin and ymax in second axis too.

The code below shows the problem:

\documentclass[12pt,twoside, a4paper]{report}
 \usepackage{tikz} 
 \usepackage{pgfplots}
\pgfplotsset{compat=1.6}
\begin{document}


\begin{tikzpicture}
\begin{axis}[filter discard warning=false,scale only axis,
  width=7.41cm,
  height=4.415cm, 
  xmin=1,xmax=9,
  ymin=0.01,ymax=100, 
  axis x line*=bottom,
  xtick = {1,2,3,4,5,6,7,8,9},
  xticklabels = {0.15, 0.25, 0.3, 0.4, 0.5, 0.8, 1.0, 1.2, 1.6},
  enlargelimits=false,axis on top=true,
  xlabel=lower x, ylabel=left y]
 \addplot[color=red,mark=x] coordinates {
 (1, 0.1) (2, 10) (3,30) (4, 45) (5, 60) (6, 72) (7, 81) (8, 80) (9,83) (10,85) };
 \end{axis}

 \begin{axis}[filter discard warning=false,scale only axis,
   width=7.41cm,
   height=4.415cm, 
   xmin=1, xmax=9,
   ymin=0.01,ymax=100, %<-comment this line and uncomment next two commented to see the scaling problem
   xtick = {1,3,5,7,9},
   xticklabels = {1,3,5,7,9},
   axis x line*=top,
   axis y line=none,
   enlargelimits=false,axis on top=true,
   xlabel=upper x]
  % \addplot[color=red,mark=x] coordinates {
 %(1, 0.1) (2, 10) (3,30) (4, 45) (5, 60) (6, 72) (7, 81) (8, 80) (9,83) (10,85)};
   \end{axis}
  \end{tikzpicture}
  \end{document}

The output as in code is:

enter image description here

and if you do the changes of the comments in above code the output gives:

enter image description here

which have fixed the 'xlabel' problem but shows the scaling problem on y axis

koleygr
  • 20,105
  • I don't really understanding why this fixes the problem... So don't accept my answer if I don't find and explain the 'why'... – koleygr Aug 28 '17 at 21:06
  • Ok... accepted. I think this was the real problem because it removes the warning: "Package pgfplots Warning: You have an axis with empty range (in direction y). R eplacing it with a default range and clearing all plots. "... So, I think this is the answer. – koleygr Aug 28 '17 at 21:22