C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-07-2009, 01:15 PM   #1
Registered User
 
Join Date: Apr 2009
Posts: 1
How to plot a graph using C

Hi.. I am a beginner in C and I work on linux platform. I need to plot a simple X-Y graph. I have the x co-ords and y co-ords saved in two different integer arrays in correspoding order. I basically need to see if I get a straight line or not. Can I please get help with a sample code or any bits that might help? Thanks a lot.
Katie_lin is offline   Reply With Quote
Old 04-07-2009, 01:28 PM   #2
Registered User
 
Join Date: Apr 2007
Posts: 46
If you are just wanting to know if it is a straight line or not (as in a yes or no answer), just ask yourself how you would check that with pen and paper, then implement the same check in code.
markcole is offline   Reply With Quote
Old 04-07-2009, 01:28 PM   #3
Super Moderator
 
Join Date: Sep 2001
Posts: 4,680
Well you can determine characteristics of the line mathematically. If you still want to visibly display the graph, you should look into a graphics library. SDL might be a good choice. (libsdl.org) Then of course you could use | \ / and -'s to display the line!
sean is offline   Reply With Quote
Old 04-07-2009, 01:33 PM   #4
Math wizard
 
Join Date: Dec 2006
Location: Minot, ND, USA
Posts: 516
An alternative is to write a BMP file. When I wanted to see how the landscape of my 2D game was going to be, I had the program write a BMP file, at 72,000x48,000 pixels and using 1-bit color. Then just open the bitmap image in a standard image-editing program. All you need to know is the BMP file's format (I like making the width a multiple of 4 for simplicity reasons (32 for the 1-bit image)), and how to change the pixel colors accordingly. 24-bit is the easiest to work with.
__________________
High elevation is the best elevation. The higher, the better the view!
My computer: XP Pro SP3, 3.17 GHz C2D CPU, 4 GB DDRII800 RAM (3 GB effective), X-Fi Platinum sound, GeForce 7600 GT, 1920x1440 resolution, 250 GB HDD, Visual C++ 2008 Express
ulillillia is offline   Reply With Quote
Old 04-07-2009, 02:27 PM   #5
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,262
If you're writing your own (not using a library) method of outputting BMP files, I'd suggest going with TGA instead. They're much simpler to figure out. If you're looking for more file types: Wotsit.org


Quzah.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Old 04-07-2009, 02:38 PM   #6
Maz
Registered User
 
Join Date: Nov 2005
Posts: 146
And if you just want to visualize the data aquired by a C program, dump values in a file, and use gnuplot to do the plotting. You can even write a script file doing the plotting using C, and launch gnuplot with simple system("") call. (or fork and exec). re-inventing the wheel can be cool and teach you a lot, but if the point is to get results...
Maz is offline   Reply With Quote
Reply

Tags
graph, linux

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
error help making no sense tunerfreak C++ Programming 5 04-17-2007 07:55 PM
problem with plot a linear graph on the command line dionys C Programming 5 04-17-2004 07:01 AM
plot a graph on the screen dionys C Programming 4 04-15-2004 02:46 PM
get the data and plot the graph lwong Windows Programming 3 01-01-2004 09:00 AM
Minimize crossing edges in undirected graph Shiro C Programming 0 12-26-2001 04:48 AM


All times are GMT -6. The time now is 07:10 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22