4

I have this tikzpicture/pgfplot (see below). I have a few questions about it.

  1. How do you put the x-labels (101, 102 and so on) on top of the x-axis?
  2. How do you point the y-axis downwards (the arrow below)?
  3. How do you place an x-label at the green vertical (at 1591Hz)?
  4. How can you put extra ticks on the y-axis without a label (eg. every unit a tick, only every third unit a label)?
  5. With those extra ticks from former question, how do you place gridlines alongside of them?
  6. Is it posssible to put a dot or a cross on the intersection red-green?
  7. Can I also put an arrow pointing to that intersection point with a text label?
  8. When I start the domain at 10 instead of 1, or when I use xmin=10, I get a white region between the y-axis and the plot/grid. How can you avoid this. I would like this plot starting with 101 at the y-axis.

Thanks very much in advance!

\documentclass{article}
\usepackage{pgf,tikz}
\usepackage{pgfplots}
\begin{document}
\usetikzlibrary{circuits.ee.IEC,graphs,patterns,calc,positioning,intersections,quotes,decorations.markings,angles,bending,arrows.meta,shapes}
\def\dBmax{0}
\def\dBmin{-12}
\def\pi{3.14159}
\def\R{1000}
\def\C{0.0000001}
\def\Fc{1/(2*\pi*\R*\C)}
\pgfplotsset{width=14.5cm,height=6cm}
\begin{tikzpicture}[scale=0.8]
  \begin{axis}[title=$Laagdoorlaatfilter-verzwakking$,
      axis lines=middle,
      ymin=\dBmin,ymax=\dBmax,
      ylabel={$A_v(dB)$},
      ylabel style={at={(ticklabel* cs:1)},anchor=east},
      ytick={-21,-18,...,0},
      xmode=log,
      domain=1:100000,
      xlabel={$f(Hz)$},
      xlabel style={at={(ticklabel* cs:1)},anchor=south},
      xtick style={above=1cm},
      xminorticks=true,
      xmajorticks=true,
      xminorgrids,
      xmajorgrids,
      grid=both,
      samples=100]
    \addplot[no marks, blue] {20*log10(1/sqrt(1+(2*\pi*\R*\C*x)^2))};
%    \addplot+[no marks, green] {20*log10(1/sqrt(1+1/((2*\pi*\R*\C*x)^2)))};
    \addplot+[no marks, red] {-3};
    \addplot+[no marks,green!50!black] coordinates{(\Fc,\dBmax) (\Fc,\dBmin)};
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • your code is not compileable – AndréC Mar 3 at 9:02
  • I changed the code a little, should compile. – Guido VDV Mar 3 at 9:11
  • 2
    Normally, each question should be one and only one problem and not several as you did because it makes it easier for people with the same problem to find it. Problem #2 has several answers on this site, old answers that no longer apply to the latest version of pgfplots. So ask a new question and clearly specify the solutions you have tried that have not solved this problem. – AndréC Mar 3 at 16:57
5

edit: like this (solved almost all your questions ... )?

enter image description here

(red lines indicate text borders)

\documentclass{article}
\usepackage{siunitx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{tikzpicture}[pin edge={Latex-,black}]
\def\dBmax{0}
\def\dBmin{-12}
\def\pi{3.14159}
\def\R{1000}
\def\C{0.0000001}
\def\Fc{1/(2*\pi*\R*\C)}
\begin{semilogxaxis}[                             % <---
    width=\linewidth,height=6cm,                  % <---
    title=Laagdoorlaatfilter-verzwakking,
    title style = {at={(0.5,1.2)},font=\itshape}, % <---
    axis x line=top,                              % <---
    axis y line=left,                             % <---
    ymin=\dBmin, ymax=\dBmax,
    ylabel={$A_v$ (\si{\decibel})},               % <--- 
    ylabel style={at={(-0.07,0.5)}},              % <---
    ytick={\dBmin,\dBmin+3,...,\dBmax},           % <===
%   ytick={\dBmin,\numexpr\dBmin+3\relax,...,\dBmax}, % alternatively, 
    xlabel={$f$ (\si{\hertz})},
    xlabel style={at={(0.5,1.1)}},
%
    extra x tick style={% changes for x extra ticks % <===
        tick label style={font=\footnotesize,text=green!50!black}, % <===
        grid style={semithick,green},               % <===
                    },
    extra x ticks={1591},                           % <=== 
    extra x tick labels={1591},                     % <===
%
    grid=both,                                       
    minor y tick num=2,                             % <===
    domain=10:100000,                                  
    samples=100,
    no marks]
    \addplot[blue] {20*log10(1/sqrt(1+(2*\pi*\R*\C*x)^2))};
    \addplot[red]  {-3};
    \node[circle,fill, inner sep=1pt,
          pin=45:$f_c$] at (1591,-3) {};            % <===
  \end{semilogxaxis}
\end{tikzpicture}
\end{document}

note:

  • tikz libraries should always be loaded in document preamble
  • pgfplots load tikz, so it is not necessary to load it (/again)
  • better than scaling diagram is to prescribe its width, for example to be equal to text width
  • +1: $f$ in Hz (Hz upright) would be even nicer :) – Dr. Manuel Kuehner Mar 3 at 10:01
  • 1
    @Dr.ManuelKuehner, you are right. i will correct asap (with some other small glitches ...). – Zarko Mar 3 at 10:03
  • Have you had a look at the libraries you are loading and checked which of those are really needed? And \def\pi{3.14159}, really? – marmot Mar 3 at 16:55
  • @marmoth, i my mwe i only use arrows.meta for pin edge, all other i left because op have them in his mwe. it might be better to erase them ... ok. i delete all not used. thank you for point me on this. – Zarko Mar 3 at 17:00
  • @marmoth I'm just learning to use tikz and pgfplots so I'm messing with all kind of settings. Pi is the least of them, so I just define it instead of searching for another solution (don't have much time). This picture is just a part of a larger document, so the other libraries I use in other parts, didn't filter them out. – Guido VDV Mar 3 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.