1

I have a csv file with the following format.

Label 1, 20
Label 2, 10
Label 3, 30
.
.
.
LabelN, 5

How do I plot the second column using the labels given in the csv file as labels on the x-axis?

(Something like this, where 1891-1900 is a label)

EDIT:

Found these questions which are quite similar to mine,

  1. Plotting word frequency histogram using gnuplot

  2. Gnuplot xticlabels with several lines

After trying the commands given in answer 1.

set xtics border in scale 1,0.5 nomirror rotate by -90 offset character 0, 0, 0
plot "data.txt" using 2:xticlabels(1) with histogram

I'm getting a not so clean histogram because the number of labels is quite large. I've tried the formatting given in answer 2. Can anyone suggest a way to get a cleaner histogram?

6
  • You can : 1) Plot only the important labels (extremes, mean etc. for example) 2) Skip every 5th label or so if labels form a series 3) Split your graph if you must plot every single label. Can you post a sample of the original file? Commented Dec 21, 2014 at 15:50
  • @axiom, Here is the original csv file. Commented Dec 21, 2014 at 15:59
  • @axiom, I think I'll split the graph as there are so many labels. Commented Dec 21, 2014 at 16:01
  • Skipping some labels and plotting with appropriate font size gives this. Commented Dec 21, 2014 at 16:46
  • Looks clean. I think I can skip some labels. Thanks! Commented Dec 21, 2014 at 16:53

1 Answer 1

1

You have several options:

  1. Plot only the important labels (extremes, mean etc. for example)
  2. Skip every 5th label or so if labels form a series
  3. Split your graph if you must plot every single label.

Seems like case 2) applies here, and thus skipping some of the labels before plotting will make the plot look better.

You can pre-process the file to skip every 5th label (say) using something like the following script:

line_number = 0
for line in open("d1.txt", "r"):
    line_split = line.split(",")
    if(line_number % 5 == 0):
        print line,
    else:
        print ",",line_split[1],
    line_number += 1

You can now plot with appropriate font size

set xtics border in scale 1,0.5 nomirror rotate by -90 offset character 0, 0, 0
set xtics font ",9"
plot "d2.txt" using 2:xticlabels(1) with histogram title "legend_here"

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.