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

In summary: First, try "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. You can use the version of Gnuplot that you have, but it may not work with all of the parameters that you want to use. For some reason, the parameters for different line type and colors differ from terminal to terminal. Compare the
  • #1
aostraff
48
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
  • #2
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
I'm looking for the programs where I can write the graphs in file for viewing.
 
  • #4
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
Thanks. This looks like a nice piece of program I can play around with for a while.
 
  • #6
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 [Broken]
 
Last edited by a moderator:
  • #7
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
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.
 
  • #9
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 [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:
  • #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
 

1. How do I choose the right type of graph for my data?

The type of graph you choose depends on the type of data you have and the story you want to tell. For example, a scatter plot is useful for showing the relationship between two continuous variables, while a bar graph is better for comparing discrete categories. Consider the purpose of your graph and the patterns in your data when deciding on the type of graph to use.

2. How do I label my axes correctly?

Axis labels are a crucial aspect of a graph as they provide context and understanding for the data. The x-axis should represent the independent variable, and the y-axis should represent the dependent variable. Make sure to include units of measurement and a clear title for each axis to provide further clarity.

3. How do I choose the scale for my graph?

The scale of your graph should be chosen based on the range of your data. If your data is spread out, a larger scale may be necessary to show all the data points clearly. On the other hand, if your data is tightly clustered, a smaller scale may be more appropriate. It is essential to choose a scale that accurately represents the data without distorting the visual representation.

4. How do I add a trendline to my graph?

A trendline is a line that best fits the data points on a graph. This line can help show the overall trend or pattern in the data. Most graphing software and programs have a feature that allows you to add a trendline automatically. If not, you can manually add a trendline by calculating the equation of the line using regression analysis and plotting it on the graph.

5. Can I create a 3D graph with my data?

Yes, you can create a 3D graph if you have data with three variables. However, it is essential to consider if a 3D graph is the best way to represent your data. In some cases, a 3D graph can be misleading or difficult to interpret. It is crucial to carefully consider the purpose of your graph before deciding to use 3D plotting.

Similar threads

  • Programming and Computer Science
Replies
10
Views
2K
  • Programming and Computer Science
Replies
2
Views
4K
  • Introductory Physics Homework Help
Replies
14
Views
1K
  • Programming and Computer Science
Replies
5
Views
5K
  • Programming and Computer Science
Replies
8
Views
13K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Precalculus Mathematics Homework Help
Replies
11
Views
2K
Replies
1
Views
745
  • Sci-Fi Writing and World Building
Replies
7
Views
1K
Back
Top