# Producing a graph plot of points in 2D/3D

1. Feb 28, 2009

### aostraff

I was wondering if there were reasonable ways of producing a graph of a bunch of points in C. Being able to connect them with lines would be even better. I'm on Mac OS X and I use XCode if it matters.

So far, I'm not too familiar with <graphics.h>. I wouldn't mind creating my own graphics, but I can't seem to find decent resources to learn how to do it. Thanks.

2. Feb 28, 2009

### csprof2000

Do you want to do it in an interactive GUI, or do you want to write graphs to file for viewing?

There are lots of good graphic programs out there, that require only formatted file input.

3. Feb 28, 2009

### aostraff

I'm looking for the programs where I can write the graphs in file for viewing.

4. Feb 28, 2009

### csprof2000

Look up "gnuplot".

Say you have a space-delimited file, with one data point per line. E.g.

0 1
1 2
2 4
3 8
4 16
5 32
6 64
7 128

Say this file is named '2powers.dat' and it's in the C:\ directory.

Type the following:

plot '2powers.dat' u 1:2 w l

That means: plot the contents of "2powers.dat" using columns 1 and 2, connecting consecutive points with lines.

There are a slew of other commands, as well as tools for doing 3-d stuff.

5. Feb 28, 2009

### aostraff

Thanks. This looks like a nice piece of program I can play around with for a while.

6. Mar 1, 2009

### Dr Transport

You'll be playing for a while......

Try this website to get started....

http://t16web.lanl.gov/Kawano/gnuplot/index-e.html [Broken]

Last edited by a moderator: May 4, 2017
7. Mar 5, 2009

### Anglea

please can anyone help me to plot with colors in G N U P L O T
Version 4.0 patchlevel 0, as I found some commands somewhere online, but it does not work, can you plaes show me how to do it, and how to add legends.....

8. Mar 13, 2009

### buffordboy23

I have version 4.2 patchlevel 4; it's a relatively recent version. They have a "lc" command to choose the linecolor; this command does not appear in older versions.

What terminal are you outputting the graphs to? This could affect things too.

9. Mar 15, 2009

### Anglea

thanks, actually when I used the command
PHP:
set te post enhanced color
, it gives me some colors, but I need to set certain colors by using the follwing commands
PHP:
set style line 1 lt 1 lw 6
set style line 2 lt 3 lw 8 pt 7 ps 2
I am using the shell console
hope hear from you soon

10. Mar 15, 2009

### buffordboy23

Anglea,

First, type "test" at the command prompt. You should get a window that shows various parameters available for plotting (e.g. line color, type, point type, etc.). If you aren't seeing this output graph, make sure that the terminal is the default. You can use any of these options when plotting in the default terminal.

However, you will likely run into problems since you want to use the postscript terminal for your graphs. For some reason, the parameters for different line type and colors differ from terminal to terminal. Compare the output to the default terminal with the postscript terminal. Moreover, with the version of Gnuplot that you have, I found that you can't mix and match line type and line colors without manually editing the output file; see the link for more detail: http://t16web.lanl.gov/Kawano/gnuplot/postscript-e.html [Broken]. The newest version of Gnuplot permits you to mix and match as you desire.

What format do you want to save your graphs as? .eps?

EDIT: Here is an example graph and script, which will help you out with the legend and other things: http://t16web.lanl.gov/Kawano/gnuplot/gallery/nup.html [Broken]

Last edited by a moderator: May 4, 2017
11. Mar 17, 2009

### Anglea

anyone please could help me how to plot a data file with complex data, actually I have tried this command, it does not give any error messages, but also it does not show any figure, her the command,
PHP:
plot '-' using 1:(arg($1+{0,1}*$2)) ' {%lf,%lf}'
as my elements like(5, 6) complex numbers

12. Mar 20, 2009

### Anglea

I have a data file of 3 column, I want to plot it in 3 dimension as a color map, I have apply this command
Code (Text):
set term postscript eps enhanced color
set output "color.eps"
set xrange [-4:0]
set yrange [0:8]
unset key
set pm3d map
splot 'file.xyz' with points
but I did not get any plot, though the colorbox appears, also I TRIED
PHP:
splot 'file.xyz' u 1:2:3
but with nothing, anyone enlighten me please

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook