graph.py

Created by numworks

Created on April 13, 2018

653 Bytes

Ce script permet de tracer des graphes de fonctions. La fonction plotf(function,Xmin,Xmax,Ymin,Ymax) trace la fonction en premier argument dans le repère défini par Xmin, Xmax, Ymin et Ymax. Essayer par exemple plotf(sin,-10,10,-2,2). La fonction plotlist(list) trace les éléments de la liste placée en argument à raison d’un élément par pixel sur l’axe horizontal et sur un axe vertical ajusté par rapport aux valeurs contenues dans la liste. Essayer par exemple plotlist(range(320)).


from kandinsky import *
from math import *
def plotf(function,Xmin,Xmax,Ymin,Ymax):
  red=color(255,0,0)
  black=color(0,0,0)
  for pixel_x in range(320):
    X=Xmin+pixel_x*(Xmax-Xmin)/319
    Y=function(X)
    pixel_y=int((Y-Ymax)*221/(Ymin-Ymax))
    set_pixel(pixel_x,pixel_y,red)
  for x in range(320):
    y_0=int(Ymax*221/(Ymax-Ymin))
    set_pixel(x,y_0,black)
  for y in range(222):
    x_0=int(Xmin*319/(Xmin-Xmax))
    set_pixel(x_0,y,black)
def plotlist(list):
  red=color(255,0,0)
  Ymin=min(list)
  Ymax=max(list)
  length=len(list)
  for i in range(length):
    j=int((list[i]-Ymax)*182/(Ymin-Ymax)+19)
    set_pixel(i,j,red)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.