柱状图和折线图叠加?

发布于 2022-12-12 10:31:02
关注者
0
被浏览
2.5k
2 个回答
LaTeXer
LaTeXer 2022-12-12
这家伙很懒,什么也没写!

excel?还是 tikz?tikz 可以用 pgfplots 宏包:

\documentclass[border=3mm]{standalone}
    \usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[
    title=Title,
    width=7.8cm,
    enlargelimits=0.15,
    legend style={at={(0.5,-0.15)},
      anchor=north,legend columns=-1},
    ylabel={Pages},
    bar width=7mm, y=4mm,
    symbolic x coords={Firm 1, Firm 2, Firm 3, Firm 4, Firm 5},
    xtick=data,
    x tick label style={rotate=45,anchor=east},
    nodes near coords align={vertical},
    ]
\addplot[ybar, nodes near coords, fill=black!10] 
    coordinates {(Firm 1,3) (Firm 2,7) (Firm 3,8) (Firm 4,13) (Firm 5,16)};
\addplot[draw=blue,ultra thick,smooth] 
    coordinates {(Firm 1,3) (Firm 2,7) (Firm 3,8) (Firm 4,13) (Firm 5,16)};
\end{axis}
    \end{tikzpicture}
\end{document}

image.png

Sagittarius Rover
这家伙很懒,什么也没写!

仅作示范,可以画两次,第二次不要画额外的轴:

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
  \pgfplotsset{set layers}
  \begin{axis}[
    scale only axis,
    width=10cm, height=6cm,
    ybar, bar width=12pt,
    ylabel={Production (10k tons)},
    symbolic x coords={1-2, 1-3, 1-4, 1-5, 1-6, 1-7, 1-8, 1-9},
    xtick=data,
    ymin=0, ymax=8000,
    axis y line*=left,
    legend style={at={(0.5,-0.15)}, anchor=north, legend columns=-1},
    area style
  ]
    \addplot[fill=white, draw=black] coordinates {
        (1-2, 1149) (1-3, 1744) (1-4, 2314) (1-5, 2905) 
        (1-6, 3526) (1-7, 4111) (1-8, 4672) (1-9, 5263)
    };
    \addplot[fill=gray!60, draw=black] coordinates {
        (1-2, 1527) (1-3, 2362) (1-4, 3143) (1-5, 3939) 
        (1-6, 4792) (1-7, 5584) (1-8, 6348) (1-9, 7160)
    };
    \legend{Pig Iron, Crude Steel}
  \end{axis}

  \begin{axis}[
    scale only axis,
    width=10cm,height=6cm,
    axis y line*=right,
    axis x line=none,
    ylabel={Growth Rate (\%)},
    ymin=0, ymax=16,
    symbolic x coords={1-2, 1-3, 1-4, 1-5, 1-6, 1-7, 1-8, 1-9}
  ]
    \addplot[mark=square*,thick] coordinates {
        (1-2, 7.1) (1-3, 8.0) (1-4, 6.8) (1-5, 5.8) 
        (1-6, 5.6) (1-7, 5.4) (1-8, 5.0) (1-9, 4.9)
    };
    \addplot[mark=triangle*,thick] coordinates {
        (1-2, 13.7) (1-3, 11.0) (1-4, 8.7) (1-5, 8.2) 
        (1-6, 9.3) (1-7, 9.5) (1-8, 9.3) (1-9, 9.3)
    };
  \end{axis}
\end{tikzpicture}
\end{document}

image.png

另外提问要给代码,即使你不能画出双轴,你也应给出绘制单轴的代码。

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览