473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

2d graphics - what module to use?

What is the easiest way to draw to a window? I'd like to draw something
like sine waves from a mathematical equation.
Newbie to python.
Jul 25 '08 #1
8 8796
Use python's default GUI tkinter's drawing functions or you can use
wxPython GUI kit or you can use pyopengl.
If you are only interested to draw sin waves or math functions that
you should give try to matlab at www.mathworks.com

Jul 25 '08 #2
On 25 Lug, 08:13, Pierre Dagenais <pierre.dagen...@ncf.cawrote:
What is the easiest way to draw to a window? I'd like to draw something
* like sine waves from a mathematical equation.
Newbie to python.
What you are really asking for is what GUI library you should use;
every one allows you to draw freely. What do you need to do besides
drawing sine waves? You should look at your full range of options;
http://wiki.python.org/moin/GuiProgramming is a good starting point.

The "easiest" way to draw might be with those toolkits that offer
primarily a canvas to draw on rather than composable widgets. For
example, Pyglet (http://pyglet.org/) offers OpenGL contexts with
sensible defaults and unobtrusive automation:

from pyglet import *
from pyglet.gl import *
import math
win = window.Window(width=700, height=700, caption="sine wave demo",
resizable=True)
frequency,phase,amplitude=0.1,0.0,0.9
@win.event
def on_draw():
half_height=win.height*0.5
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(0.9, 1.0, 0.8)
glBegin(GL_LINE_STRIP)
for x in xrange(0,win.width):
y=half_height*(1.0+amplitude*math.sin(x*frequency+ phase))
glVertex2f(x,y)
glEnd()
app.run()

Regards,

Lorenzo Gatti
Jul 25 '08 #3
On Fri, Jul 25, 2008 at 2:13 AM, Pierre Dagenais <pi*************@ncf.cawrote:
What is the easiest way to draw to a window? I'd like to draw something
like sine waves from a mathematical equation.
Newbie to python.
--
http://mail.python.org/mailman/listinfo/python-list
I'd recommend matplotlib:

http://matplotlib.sourceforge.net/

Also see the "GUI" and "Plotting" sections on this page:

http://wiki.python.org/moin/UsefulModules
Jul 25 '08 #4
Pierre Dagenais wrote:
What is the easiest way to draw to a window? I'd like to draw something
like sine waves from a mathematical equation.
Newbie to python.
--
http://mail.python.org/mailman/listinfo/python-list
For very simple things, the standard module turtle might be your best bet.

BB

Jul 25 '08 #5
On Jul 25, 8:13*am, Pierre Dagenais <pierre.dagen...@ncf.cawrote:
What is the easiest way to draw to a window? I'd like to draw something
* like sine waves from a mathematical equation.
Newbie to python.
For mathematica equations, NumPy and matplotlib is probably the best
option. I prefer to embed matplotlib in wxPython. wxAgg is an
excellent backend.

For more general 2D graphics, there are several options, including:

- pygame (uses SDL)
- aggdraw module
- pycairo
- pyopengl
- wxPython's device context (ditto for other GUI libraries)

Jul 25 '08 #6
sturlamolden wrote:
On Jul 25, 8:13 am, Pierre Dagenais <pierre.dagen...@ncf.cawrote:
>What is the easiest way to draw to a window? I'd like to draw something
like sine waves from a mathematical equation.
Newbie to python.

For mathematica equations, NumPy and matplotlib is probably the best
option. I prefer to embed matplotlib in wxPython. wxAgg is an
excellent backend.

For more general 2D graphics, there are several options, including:

- pygame (uses SDL)
- aggdraw module
- pycairo
- pyopengl
- wxPython's device context (ditto for other GUI libraries)

--
http://mail.python.org/mailman/listinfo/python-list
If you're using wx, there is also wx.lib.plot, which I found to be
_much_ faster than matplotlib in my application, especially when resizing.

-Matt
Jul 26 '08 #7
On Jul 25, 4:10*am, King <animator...@gmail.comwrote:
Use python's default GUI tkinter's drawing functions or you can use
wxPython GUI kit or you can use pyopengl.
If you are only interested to draw sin waves or math functions that
you should give try to matlab atwww.mathworks.com
If you're only interested in sine waves you most certainly should not
give Matlab a try; even with student pricing it's going to be way
expensive for something that simple.

For just popping up a window and drawing on it I recommend PyGame.
Carl Banks
Jul 26 '08 #8
On Jul 26, 6:47*am, Matthew Fitzgibbons <eles...@nienna.orgwrote:
If you're using wx, there is also wx.lib.plot, which I found to be
_much_ faster than matplotlib in my application, especially when resizing..
Yes. Matplotlib creates beautiful graphics, but are terribly slow on
large data sets.
Jul 26 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Brent W. Hughes | last post by:
If the Turtle gets himself into a large (or infinite) loop, is there any way to stop him other than Ctrl-Alt-Del? Brent
4
by: Steven Feil | last post by:
I am wondering if there is a light weight Python library for producing web graphics on-the-fly. There is a C-language library called gd that can be used in a CGI program to produce gif images. The...
5
by: Markus Elfring | last post by:
Hello, A lot of clipart libraries offer free raster images. I am looking for a similar collection for vector graphics. Do you know a gallery or archive for the following formats? - Scalable...
2
by: Matt Silberstein | last post by:
I wanted to make a script to build a thumbnail library. So I went to cpan.org and find the various GD modules. So I run ppm3 (I am running on XP) and search for GD. No luck. But cpan also lists...
3
by: Anton81 | last post by:
Hi, I want to use globals that are immediately visible in all modules. My attempts to use "global" haven't worked. Suggestions? Anton
3
by: Harley | last post by:
I am trying to build graphic charts in a vb.net module callable from another form. I have translated this code from VB6 where it worked well. I can make the code work to bring up and display the...
7
by: Dick Moores | last post by:
I accidentally stumbled across the Turtle Graphics module (turtle.py) the other day and have been having some fun with it. Now I'm wondering if there is a way to build into a script the saving...
1
thatos
by: thatos | last post by:
Which website can I go to get grahics.py module
1
by: evilcraft_mj | last post by:
when i type from graphics import * error shown that there is no such module called graphics. help me find this......
2
by: Gabriel | last post by:
Hi all ! I'm developing a math program that shows graphics of functions. I would hear suggestions about the way of drawing 2D . Thanks a lot for your answers. - Gabriel -
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.