TransWikia.com

Pgfplots plots incorrect lines from function to axis

TeX - LaTeX Asked by Overclock on March 16, 2021

I’m using Beamer with Pgfplots. I have a graph that needs to have a series of dashed lines going from a function (trigonometric, intended to be in radian) to the x-axis. The file runs without giving errors but some of the lines don’t plot as expected. I originally thought it might be a degree/radian issue, but that doesn’t seem to be it, as setting everything to radians just makes the problem worse. In the code I’ve left some of the lines with the default degree input and some of them with the r option so it’s clear that neither case is plotting properly. How do I fix this?

MWE:

documentclass[10pt,handout]{beamer}
setbeamercovered{dynamic}
mode<presentation>

usepackage{pgfplots}
pgfplotsset{compat=1.17}
usepackage{amsmath}
usetikzlibrary{calc}
pgfplotsset{ trig format plots = rad }
begin{document}

    begin{frame}

        begin{tikzpicture}
            begin{axis}[ axis lines = middle, ticks=none, xlabel=$x$, ylabel=$y$, xmin = 0, xmax = 2.3, ymin = 0, ymax = 1.5, clip = false, declare function = {
        f(x) = 5*cos(x)*(sin(x))^(10) + .2*(cos(x))^9 *exp(sqrt(x)) + 0.25;
        },
        every axis x label/.style={ at={(ticklabel* cs:1)}, anchor=north},
        every axis y label/.style={ at={(ticklabel* cs:1)}, anchor=east}]
                addplot[thick, green!60!black, domain = 0.4:1.8, samples = 400] {f(x)};    
                
                pgfplotsforeachungrouped i/j in {{0.4}/{0}, {0.7}/{1},{0.85}/{2}, {1}/{3}}{
                    edeftinker{noexpanddraw[cyan, dashed] (i, {f(i)})--(i, 0) node[below]{$x_j$};}
                    tinker
                }
                
                pgfplotsinvokeforeach {1.05, 1.1,..., 1.8} {
                    draw[cyan, dashed] (####1, {f(####1 r)})--(####1, 0);
                }
            end{axis}
        end{tikzpicture}

    end{frame}
end{document}

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP