#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep 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 ?
    Thanks in advance.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    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 and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    Thanks for the reply
    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 ?

    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)
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    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.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    608
    Rep Power
    65
    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

IMN logo majestic logo threadwatch logo seochat tools logo