Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

#1
November 18th, 2012, 03:38 PM
 jag_chandra
Registered User

Join Date: Nov 2012
Posts: 2
Time spent in forums: 18 m 51 sec
Reputation Power: 0
Drawing isosceles triangle using python Pyplot/Matplotlib

Hi all,
I'm trying to plot to isosceles triangle with two equals sides with * using pyplot or matplot lib module in python.
I couldn't find api to draw triangle and i'm not very familiar with the library. Does anyone know how to do it ?

#2
November 19th, 2012, 10:21 AM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 3,384
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 48 m 49 sec
Reputation Power: 383
Why do you need matplotlib or pyplot? Why does your isosceles triangle need two equals sides?
Code:
```try:
import Tkinter as tkinter
except:
import tkinter

import time

iso = ((10,10,40,50,70,10,),(180,50,120,180,60,50,),)
canvas = tkinter.Canvas(width=400,height=200)
canvas.pack()
polygon = canvas.create_polygon(*(iso[0]))
colors = 'red green blue yellow orange'.split()
for i in range(9):
canvas.coords(polygon,*(iso[i&1]))
canvas.itemconfig(polygon,fill=colors[i%len(colors)])
canvas.update()
time.sleep(1)```
__________________
[code]Code tags[/code] are essential for python code!

#3
November 19th, 2012, 11:09 AM
 jag_chandra
Registered User

Join Date: Nov 2012
Posts: 2
Time spent in forums: 18 m 51 sec
Reputation Power: 0
It can be either matplotlib or pyplot but it has to be one of them as i've requirement to use one of them .

Why does your isosceles triangle need two equals sides?
Isosceles triangles have two equal sides

Isn't tkinter different library altogether or is it part of matplotlib ?

Quote:
 Originally Posted by b49P23TIvg Code: ```try: import Tkinter as tkinter except: import tkinter import time iso = ((10,10,40,50,70,10,),(180,50,120,180,60,50,),) canvas = tkinter.Canvas(width=400,height=200) canvas.pack() polygon = canvas.create_polygon(*(iso[0])) colors = 'red green blue yellow orange'.split() for i in range(9): canvas.coords(polygon,*(iso[i&1])) canvas.itemconfig(polygon,fill=colors[i%len(colors)]) canvas.update() time.sleep(1)```

#4
November 19th, 2012, 11:30 AM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 3,384
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 48 m 49 sec
Reputation Power: 383
http://exnumerus.blogspot.com/2011/02/how-to-quickly-plot-polygons-in.html

you wrote the redundant sentence

And what do you mean by "with *"?

Yes, tkinter uses tcl. matplotlib seems to use gtk.

#5
November 19th, 2012, 12:31 PM
 Dietrich
Contributing User

Join Date: Feb 2005
Posts: 483
Time spent in forums: 3 Days 22 h 51 m 26 sec
Reputation Power: 63
Experiment with something like that:
Code:
```import matplotlib.pyplot as plt

plt.plot([1,2,3])

plt.plot([3,2,1])

plt.plot([2,2,2])

plt.show()```
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Drawing isosceles triangle using python Pyplot/Matplotlib