不曲折的图形表示

不曲折的图形表示

我尝试编译以下代码来绘制由值数组定义的一些函数的图形。

代码如下

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\pgfplotstableread[col sep=comma]{
-1,             1, -3.88461538461538,10.8768115942029,-49.37372620793093, 175.3383368168327, 
-0.35714286,    1, -3.24175824175824,6.566474415853299,-23.612493710583458, 55.10682373726086, 
 0.28571429,    1, -2.59890109890110,3.082667849748595, -6.732218933226122, -2.520938957827919, 
 0.92857143,    1, -1.95604395604396,0.4253918958887899, 2.8611214477562354, -19.7847951798583, 
 1.57142857,    1, -1.31318681318681,-1.4053534457261168,6.761550755978779, -14.825671722387444, 
 2.21428571,    1, -0.67032967032967,-2.409568175096126, 6.563092315056663, -1.6855782611049153, 
 2.85714286,    1, -0.02747252747252,-2.5872522922212347, 3.859769448605049, 9.692392646167214, 
 3.5,           1,  0.61538461538461, -1.9384057971014481, 0.24560548023911766, 13.464065559474449, 
 4.14285714,    1,  1.25824175824176, -0.4630286897367631, -2.6853762664260006, 7.884182156729922, 
 4.78571429,    1,  1.90109890109890, 1.838879029872821, -3.339152467775138, -4.693598766285728, 
 5.42857143,    1,  2.54395604395604, 4.967317361727301, -0.12169980019311577, -17.8167012959243, 
 6.07142857,    1,  3.18681318681319, 8.922286305826688, 8.561005059935194, -20.933632400670078,
 6.71428571,    1,  3.82967032967033, 13.703785862170964, 24.302985436225047,  0.606018068859953, 
 7.35714286,    1,  4.47252747252747, 19.31181603076014, 48.698264652291485, 65.55157737991703, 
 8,             1,  5.11538461538462, 25.746376811594203,83.34086603174967 ,196.75128991761915,

 
}\loadedtable

\begin{tikzpicture}
    \begin{axis}[
axis lines=center,
xmin=-1.5,  xmax=8.5,
ymin=-50,  ymax=190,
axis on top,
xtick distance=1,
ytick distance=20,
tick label style={font=\footnotesize, inner sep=1pt, fill=white},
no marks, samples=15,
every axis plot post/.append style={very thick}
                ]
\addplot table[x index=0,y index=1] {\loadedtable};
\addplot table[x index=0,y index=2] {\loadedtable};
\addplot table[x index=0,y index=3] {\loadedtable};
\addplot table[x index=0,y index=4] {\loadedtable};
\addplot table[x index=0,y index=5] {\loadedtable};
    \end{axis}
\end{tikzpicture}

\end{document}

结果:

在此处输入图片描述

我希望图形表示不呈锯齿状。请提供想法。

答案1

  • 看来你问题中的代码是基于我的回答 对于您之前的问题,但您没有接受它也没有赞成...如果您现在这样做,那将会很好也很公平。
  • 样本数量太少,函数曲线看起来会更平滑,因此,您需要在给定的样本之间插入它们的值。
  • 这可以通过宏来实现smooth,该宏通过使用样条函数在给定样本之间插值函数。
  • smooth您可以添加到轴选项的宏:
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\pgfplotstableread[col sep=comma]{
-1,             1, -3.88461538461538,   10.8768115942029,   -49.37372620793093,     175.3383368168327,
-0.35714286,    1, -3.24175824175824,    6.566474415853299, -23.612493710583458,     55.10682373726086,
 0.28571429,    1, -2.59890109890110,    3.082667849748595,  -6.732218933226122,     -2.520938957827919,
 0.92857143,    1, -1.95604395604396,    0.4253918958887899,  2.8611214477562354,   -19.7847951798583,
 1.57142857,    1, -1.31318681318681,   -1.4053534457261168,  6.761550755978779,    -14.825671722387444,
 2.21428571,    1, -0.67032967032967,   -2.409568175096126,   6.563092315056663,     -1.6855782611049153,
 2.85714286,    1, -0.02747252747252,   -2.5872522922212347,  3.859769448605049,      9.692392646167214,
 3.5,           1,  0.61538461538461,   -1.9384057971014481,  0.24560548023911766,   13.464065559474449,
 4.14285714,    1,  1.25824175824176,   -0.4630286897367631, -2.6853762664260006,     7.884182156729922,
 4.78571429,    1,  1.90109890109890,    1.838879029872821,  -3.339152467775138,     -4.693598766285728,
 5.42857143,    1,  2.54395604395604,    4.967317361727301,  -0.12169980019311577,  -17.8167012959243,
 6.07142857,    1,  3.18681318681319,    8.922286305826688,   8.561005059935194,    -20.933632400670078,
 6.71428571,    1,  3.82967032967033,   13.703785862170964,  24.302985436225047,      0.606018068859953,
 7.35714286,    1,  4.47252747252747,   19.31181603076014,  48.698264652291485,      65.55157737991703,
 8,             1,  5.11538461538462,   25.746376811594203, 83.34086603174967,      196.75128991761915,
}\loadedtable

\begin{tikzpicture}
    \begin{axis}[
axis lines=center,
xmin=-1.5,  xmax=8.5,
ymin=-50,  ymax=190,
axis on top,
xtick distance=1,
ytick distance=20,
tick label style={font=\footnotesize, inner sep=1pt, fill=white},
no marks, samples=15, smooth,
every axis plot post/.append style={very thick}
                ]
\addplot table[x index=0,y index=1] {\loadedtable};
\addplot table[x index=0,y index=2] {\loadedtable};
\addplot table[x index=0,y index=3] {\loadedtable};
\addplot table[x index=0,y index=4] {\loadedtable};
\addplot table[x index=0,y index=5] {\loadedtable};
    \end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

编辑:
但是,如果绘图时使用函数(如@Teepeemm 在其评论中所建议的那样),您将获得更好、更准确的结果,从中计算出的值会收集到表中。在这种情况下,您可以定义更多样本,例如 101 个甚至更多,而不再使用smooth宏。

例如,上述 MWE 中的第五个函数定义如下:

(x-3.5)^4-12*(x-3.5)^2+12

(我的近似值,你应该使用一个,从中计算表中收集的样本)比 MWE 可以是:

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

    \begin{tikzpicture}
\begin{axis}[
axis lines=center,
xmin=-1.5,  xmax=8.5,
ymin=-50,  ymax=190,
axis on top,
xtick distance=1,
ytick distance=20,
tick label style={font=\footnotesize, inner sep=1pt, fill=white},
no marks, 
domain=-1:8, samples=101,                % domain and samples, no smooth macro
every axis plot post/.append style={very thick}
                ]
\addplot    {(x-3.5)^4-12*(x-3.5)^2+12}; % my approximation of your function
                                         % you should insert here your formula
\end{axis}
    \end{tikzpicture}
\end{document}

结果是:

在此处输入图片描述

\addplot类似地,您可以绘制其他函数。只需在指令中使用它们的数学表达式即可。

相关内容