How do I set the precise intervals that pgfplots should consider when performing addplot
with the option const plot mark mid
? For example:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\pgfplotsset{compat=1.9}
\begin{filecontents*}{data.csv}
1., 1.
2., 2.
4., 3.
7., 4.
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[const plot mark mid, mark=*] table [col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}
The issue is that when you have an input table which is irregular in the x-axis, pgfplots divides the intervals in a not so convenient way. It simply ends the "step" in the middle way to the next mid point. So, I would like to set the intervals by hand.
Output:
In this case, I would like to correct it by providing a list of widths
{1.,1.,3.,3.}
to cover the following intervals:
0.5 -- 1.5
1.5 -- 2.5
2.5 -- 5.5
5.5 -- 8.5
This way, the points would be exactly in the middle of the steps.
Additional comment
Pgfplots documentation says that one can avoid the vertical line being drawn in the middle way between two adjacent points, by using jump mark mid
. In my example it would be
\addplot[jump mark mid, mark=*] table [col sep=comma] {data.csv};
Nevertheless, this does not solve the problem, as the horizontal lines are kept identical.
Best Answer
I came up with the following solution, which requires the inclusion of an additional column in the original table. Such additional column must contain the widths I referred in my question.
The code is divided in 3 distinct plots:
const plot
shifted (-) by half of the corresponding widths (black line); andjump mark right
shifted (+) by half width, for drawing the last step (dashed red line).The last item requires ignoring most of the points in
data.csv
by usingskip coords between index={\yini}{\yfin}
.\yini
andyfin
are defined in an automatized way.