x 轴刻度偏移

x 轴刻度偏移

我有一段代码可以绘制两个 x 轴和一个 y 轴。但是我无法控制上方 x 轴的刻度。

\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}

在第二个 x 轴上,我想将刻度分成 {1,3,5,7,9},但它从 3 开始。你能帮帮我吗?在此处输入图片描述

答案1

该问题是由不同的(非) y 缩放引起的。

在第二个轴上也ymin添加相同的内容。ymax

下面的代码显示了这个问题:

\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}

代码中的输出为:

在此处输入图片描述

如果你对上面代码中的注释进行修改,则输出结果如下:

在此处输入图片描述

已修复“xlabel”问题,但显示 y 轴上的缩放问题

相关内容