Menu

#279 Using data from file as label

None
closed
nobody
None
5
2024-09-26
2022-12-03
No

I am trying to use the data from a csv file as a label for a plot. I am getting the data displayed on the plot but it is not on the same line, it is graduated down. What I want is the 2 x | on the same line with the C on the line above it. Any help appreciated.
This is the code I’m using to generate the plot below

plot 'test-data.csv' using 1:3 w lines, 'test-data.csv' using 1:3:4 with labels offset 0, 5 font "Times,8"

Data file & image of results is attached
Peter

2 Attachments

Discussion

  • Peter Newton

    Peter Newton - 2022-12-03

    As requested this is the script that generated the image in the request
    Regards
    Peter

     
  • Ethan Merritt

    Ethan Merritt - 2022-12-03

    You have plotted each character at the y coordinate of that data point. The data points are not all at the same y, so of course the characters do not line up.

    Your "this is what I want" text is at y=0.00000030
    To produce that for all labels, use

    plot  'test-data.csv' using 1:(0.00000030):4 with labels font "Times,8"
    

    No additional offset is necessary.

     
  • Ethan Merritt

    Ethan Merritt - 2022-12-03

    Or how about this. If there were distinct 'open' and 'close' symbols it would be simpler. As it is you must rely on an assumption that the vertical bar occurs exactly twice per label.

    yval = 0
    level(char) = (char eq "|") ? (yval == 0 ? (yval=column(3)) :  (oldval=yval, yval=0, oldval)) : yval
    
    plot 'test-data.csv' using 1:3 w lines, 'test-data.csv' using 1:(level(strcol(4))):4 with labels offset 0, 5 font "Times,8" 
    

    That sort of works with your data, but the x-spacing is to close together so the characters making up a label overlap with each other. I don't think you can fix that in a single-pass command. You would have to make one pass over the data to construct the labels, then a second pass to plot them.

     
  • Peter Newton

    Peter Newton - 2022-12-04

    Ethan,
    Thank you for your suggestions, they have been a big help. It looks as though I will have to use 2 columns of data for this. One for the markers and the other for the C1.2 with an offset.
    Regards
    Peter

     
  • Ethan Merritt

    Ethan Merritt - 2024-09-26
    • status: open --> closed
     

Log in to post a comment.