TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a problem with finding the correct way or commands to make a nice plot in TeX, even with some basic experience in pgf/TikZ.

Imagine a weight distribution with start- and stop values and a line load, given in CSV-data with about 150 rows. For example something like this:

x-start [m] | x-stop [m] | weight [t/m]  
-3;   5; 2.5  
2;   4 ; 5.6  
2.45;  6.33 ; 0.25  
-1; 2.3; 4  
4; 5 ; 7.8

I would like to generate a plot with the added up weight over x. As you might see, it is difficult to deal with the loads given as extensions, overlapping areas and having no discrete points.

I would be very glad, if you have some ideas for solving this problem or giving some hints! At the moment I'm thinking of evaluating weights at discrete points, adding them up, but I think there is a more correct and satisfying way :-)

share|improve this question
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say "thank you" to users who helped you. – Peter Jansson Mar 12 '13 at 17:33
Could you include a mockup of what you want the result to look like? – Jake Mar 12 '13 at 17:38
Also can you make your question less specialized? I can't imagine what that distribution is used or looks like. – percusse Mar 12 '13 at 23:52

You are right, discretization looks to be the simplest way to go. Here is a complete MWE using the asymptote package:

# x-start [m] | x-stop [m] | weight [t/m]  
-3, 5, 2.5  
2, 4, 5.6  
2.45, 6.33, 0.25  
-1, 2.3, 4  
4, 5, 7.8
import graph;
file fin=input("wd.csv").csv();
real[][] A=fin.dimension(0,3);                               
real[] xStart=A[0];
real[] xStop=A[1];
real[] weight=A[2];
int rows=xStart.length;
real lmin=min(xStart);
real lmax=max(xStop);
real dl=lmax-lmin; // total length
int n=200; // resolution, the number of intervals
real[] PointY=new real[n+1];
PointY[:]=array(PointY.length,0.0); // initialize with 0
int beg,fin;
for(int i=0;i<rows;++i){
  for(int j=beg;j<=fin;++j){
real[] PointX=new real[PointY.length];
for(int i=0;i<PointX.length;++i){
pen p=orange+2pt;
real xmin,xmax;
real ymin,ymax;
xaxis("$x$,\,m",xmin,xmax, RightTicks());
\caption{Added up line loads}

Copy this MWE into wd.tex in a separate folder, create file latexmkrc:

sub asy {return system("asy '$_[0]'");}

and run latexmk -pdf wd.tex. The result looks like

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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