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

Click For Summary

Discussion Overview

The discussion revolves around methods for producing 2D and 3D graph plots of points using the Gnuplot software in the C programming environment. Participants explore various commands, file formats, and graphical outputs, as well as seek assistance with specific plotting challenges.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning
  • Experimental/applied

Main Points Raised

  • One participant inquires about producing graphs of points in C, expressing a desire to connect them with lines and mentioning their use of Mac OS X and XCode.
  • Another participant asks whether the graphs should be interactive or saved to a file for viewing, suggesting that many graphic programs accept formatted file input.
  • A participant specifies their interest in programs that allow writing graphs to files for later viewing.
  • Gnuplot is recommended as a suitable tool, with an example provided for plotting data from a space-delimited file.
  • One participant expresses appreciation for Gnuplot and shares a resource link for getting started.
  • Several participants seek help with plotting colored graphs in Gnuplot, mentioning version differences and specific commands for line colors and legends.
  • Another participant discusses issues with plotting complex data, noting that their command does not produce any figure despite not generating error messages.
  • A participant describes attempts to plot a three-column data file in 3D as a color map, detailing the commands used and the lack of output despite the color box appearing.

Areas of Agreement / Disagreement

Participants express various challenges and seek solutions, but there is no consensus on the best methods or commands for specific plotting issues. Multiple competing views and approaches remain throughout the discussion.

Contextual Notes

Participants mention different versions of Gnuplot, which may affect command availability and functionality. There are also references to specific terminal types that could influence plotting outcomes.

aostraff
Messages
48
Reaction score
0
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.
 
Technology news on Phys.org
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.
 
I'm looking for the programs where I can write the graphs in file for viewing.
 
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.
 
Thanks. This looks like a nice piece of program I can play around with for a while.
 
aostraff said:
Thanks. This looks like a nice piece of program I can play around with for a while.

You'll be playing for a while...

Try this website to get started...

http://t16web.lanl.gov/Kawano/gnuplot/index-e.html
 
Last edited by a moderator:
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...
 
Anglea said:
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...

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.
 
buffordboy23 said:
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.

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
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 . 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
 
Last edited by a moderator:
  • #11
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
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:
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
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 8 ·
Replies
8
Views
14K
  • · Replies 5 ·
Replies
5
Views
6K
Replies
14
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K