我想在折线图中填充一些颜色,代码如下:
\begin{tikzpicture}
\begin{axis}[
xmin=0.09,
xmax=0.32,
ymin=0,
ymax=230,
ylabel=$num$,
xlabel=$ratio$,
height=6cm,
width=8cm,
grid=major,]
\addplot [black, fill=red!20] plot [smooth]
coordinates {
(0.09, 196)
(0.1 , 215)
(0.11, 207)
(0.12, 203)
(0.13, 205)
(0.14, 191)
(0.15, 194)
(0.16, 193)
(0.17, 180)
(0.18, 159)
(0.19, 130)
(0.2 , 78)
(0.21, 71)
(0.22, 59)
(0.23, 70)
(0.24, 55)
(0.25, 54)
(0.26, 48)
(0.27, 46)
(0.28, 48)
(0.29, 54)
(0.3 , 45)}
-- (0.09,0)-- (0.3,0) -- cycle;
\end{axis}
\end{tikzpicture}
但我得到的是这样的数值?
有人知道为什么该区域没有关闭吗?谢谢。
答案1
可以告诉 tikz 使用水平线和垂直线而不是直线|-
:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0.09,
xmax=0.32,
ymin=0,
ymax=230,
ylabel=$num$,
xlabel=$ratio$,
height=6cm,
width=8cm,
grid=major,]
\addplot [black, fill=red!20] plot [smooth]
coordinates {
(0.09, 196)
(0.1 , 215)
(0.11, 207)
(0.12, 203)
(0.13, 205)
(0.14, 191)
(0.15, 194)
(0.16, 193)
(0.17, 180)
(0.18, 159)
(0.19, 130)
(0.2 , 78)
(0.21, 71)
(0.22, 59)
(0.23, 70)
(0.24, 55)
(0.25, 54)
(0.26, 48)
(0.27, 46)
(0.28, 48)
(0.29, 54)
(0.3 , 45)}
|- (0,0) |- cycle;
\end{axis}
\end{tikzpicture}
\end{document}