I have highly dimensional data for which I'd like to draw a plot where I vary the line-width, somewhat similar to the famous Minard chart:
I suspect this can be done with some combination of point meta
and line width={\pgfplotspointmetatransformed/1000 * 2pt}
somewhere, but I can't quite figure out how to do this. For scatter-plots with markers I found how to do this (pgfplots
manual, version 1.5, page 84), and varying the colour can be done using a 1-D coloured mesh plot. Linked below is a way to fix this for quiver plots, and below I linked a question how to do this in 'pure' tikz
. Maybe it would be possible with a clever decoration (fill a rectangle perpendicular to the plot?) but I suspect this would not look very nice (I haven't tried this yet). I could fill the area between y-dy and y+dy, but this is not the same as varying the line width, because the area that is filled is estimated into ±y, not perpendicular to the local line direction.
My data are discrete, so the varying line width can be, too (NOTE: see update below!). Maybe it can be done with a for
-loop. The question is:
- How do I vary the line width of a
pgfplots
-plot according to a particular function?
Some sample data, where I would plot column 1 as a function of column 0, and seek to map column 2 to the line-width:
2006 5213 48
2007 5112 47
2008 5260 49
2009 5161 53
2010 4647 57
2011 4413 62
2012 4309 65
Bonus question: If this succeeds, it would be very neat if I could draw a very thin grid through this line, so that the line width can be more easily seen. Not even Minard has done this :)
EDIT 2012-06-01: contrary to an earlier answer I gave to a comment, I realise now that I'm really looking for a continuously changing line width, e.g. an appropriately calculated and filled polygon. Using calc
and intersections
I can get the result below, but I haven't yet managed to get it into a plot (though this question on using a macro as a coordinate or this one on consistency with tikz and pgfplots might help), and of course I should automate it with my input data (with pgfplotstable
). I like the geometric calculations with calc
, but otherwise I'm beginning to suspect it may be easier for me to calculate the corners of the polygon externally and then filling them with pgfplots
later. OTOH it would be cool to have a solution where I can plug in any series of numbers (particularly since my final plot will contain many such lines).
\documentclass{standalone}
\usepackage{pgfplots,pgfplotstable}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\begin{document}%
\begin{tikzpicture}
\begin{axis}
\coordinate (a) at (0, 0);
\coordinate (b) at (1, 3);
\coordinate (c) at (2, 1);
\coordinate (aba) at ($(a)!.01cm!90:(b)$);
\coordinate (abb) at ($(a)!.01cm!-90:(b)$);
\coordinate (baa) at ($(b)!.04cm!90:(a)$);
\coordinate (bab) at ($(b)!.04cm!-90:(a)$);
\coordinate (bca) at ($(b)!.04cm!90:(c)$);
\coordinate (bcb) at ($(b)!.04cm!-90:(c)$);
\coordinate (cba) at ($(c)!.1cm!90:(b)$);
\coordinate (cbb) at ($(c)!.1cm!-90:(b)$);
\coordinate (lowsect) at (intersection of abb--baa and cba--bcb);%a_1--a_2 and b_1--b_2);
\coordinate (hisect) at (intersection of aba--bab and cbb--bca);%a_1--a_2 and b_1--b_2);
\addplot[fill=black] coordinates {(abb) (lowsect) (cba) (cbb) (hisect) (aba)} -- cycle;
%\path[fill=black] (abb) -- (lowsect) -- (cba) -- (cbb) -- (hisect) -- (aba) -- cycle;
\end{axis}
\end{tikzpicture}
\end{document}
Related questions: