I am trying to plot a best-fit trendline to an I-V curve for a Zener diode. The data is exponential so linear regression is not suitable in this instance.

Here is my data. The important columns are 2 and 3, which are current and voltage, respectively. In this case, the current data is being plotted as a function of voltage.

column 1,column 2,column 3










Here is part of the code I am working with:

\usepackage{tikz, pgfplots, pgfplotstable, siunitx}


  round-mode = places,
  round-precision = 2,


          grid style={dashed,gray!30},
          x unit=\si{\volt}, 
          y unit=\si{\milli\ampere},
          legend style={at={(0.5,1.4)},anchor=north},
          x tick label style={rotate=90,anchor=east}
        \addplot [only marks, mark = *, blue] table[x=column 3,y=column 2,col sep=comma]{tables/Table 6.csv};
    \caption{Zener diode reverse bias}

  • 1
    In my memory, linear regression is as far as what TikZ can do. You are asking too much for it to fit an exponential curve. Maybe you need to use some other programmes like MATLAB, Origin or others to calculate the curve first which is very easy. (By the way, matlab2tikz works well if you use MATLAB.) Feb 5, 2022 at 4:36
  • By the way, it seems that the I-U characteristic of the diode is not actually exponential. Some smooth plot (for example smoothingspline fitting in MATLAB) will do. Feb 5, 2022 at 4:44
  • Fair enough, thanks!
    – Karoline
    Feb 5, 2022 at 11:47
  • Look into sagetex package which gives you access to Sage, an open source CAS, as well as Python. I tried plotting your data and, assuming I did it correctly, got data that didn't look anything close to exponential; so exponential regression gave a poor fit.
    – DJP
    Feb 6, 2022 at 1:07


You must log in to answer this question.

Browse other questions tagged .