Anshul Choudhary
Anshul Choudhary

Reputation: 305

How to plot random x-values in gnuplot

I have a data set with two columns, (x,y) which looks like:

4 16
1 1
5 25
3 9
7 49
0 0
2 4

Now I want to plot this in gnuplot u 1:2 in the order in which column 1 is arranged. Basically on x-axis, gnuplot should have first 4, then 1, then 5 and so on. Is it possible with gnuplot or any other plotting tool?

Upvotes: 0

Views: 324

Answers (2)

tmdavison
tmdavison

Reputation: 69116

Since you also tagged matplotlib, here's a quick script to make the same plot. You just need to plot y, then set the xticklabels to x.

import matplotlib.pyplot as plt
import numpy as np

x,y = np.genfromtxt('data.txt',unpack=True)

plt.plot(y,'ko-')
plt.gca().set_xticklabels(x)

plt.show()

enter image description here

Upvotes: 1

Christoph
Christoph

Reputation: 48390

With gnuplot you can use the row number as x-value and use the value from the first column as xtic labels:

plot 'data.txt' using 0:2:xtic(1) w lp pt 7 lw 2

enter image description here

Upvotes: 4

Related Questions