I want to plot a graph with piecewise linear interpolation from a CSV data file. Currently, I have only managed to plot a graph like the following one:
Here is my Latex code:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\begin{filecontents*}{data_to_plot.csv}
A,B
0.011,0.0031
0.021,0.0046
0.021,0.0075
0.022,0.0171
0.022,0.0135
0.023,0.0191
0.099,0.0287
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot table [x=A, y=B, col sep=comma] {data_to_plot.csv};
\end{axis}
\end{tikzpicture}
\end{document}
But, I want to plot the graph with piecewise linear interpolation like the following graph (drawn with MS Paint):
Here is the sample data (truncated):
A,B
0.0013,0.0061
0.0016,0.0046
0.0024,0.0057
0.0024,0.0036
0.0027,0.0064
0.0027,0.0047
0.0028,0.0068
...
...
0.9973,0.1514
0.9973,0.1421
0.9977,0.1169
0.9981,0.1289
0.9983,0.1896
0.9993,0.1335
0.9999,0.1547
So, my question is: how can I plot like this, possibly with customizing the X value gaps (it is 0.1 shown in the second figure)?



filecontentspackage (for example as\begin{filecontents}{test.csv} x y -2 7 -1 2 0 5 1 4 2 8 \end{filecontents}) – Zarko May 14 '19 at 16:14xcoordinates. see, ifeach nth point={<desired value>}(adding totableoptions gives something close to what you after. – Zarko May 14 '19 at 17:11yvalues, not just nthyvalues. Though I know how to calculate them mathematically, I cannot figure out how to do it in Latex. – arnobpl May 14 '19 at 18:33lua). use programs like Mathematica or Matlab and result use as new data. for your plot. – Zarko May 14 '19 at 18:36