grafico.py

Created by numworks-pt

Created on March 10, 2020

655 Bytes

Este script permite traçar gráficos de funções. A função plotf(function,Xmin,Xmax,Ymin,Ymax)traça a função como primeiro argumento no quadro definido por Xmin, Xmax, Ymin e Ymax. Experimente por exemplo plotf(sin,-10,10,-2,2). A função plotlist(list)traça os elementos da lista colocados como argumento à taxa de um elemento por pixel no eixo horizontal e num eixo vertical ajustado aos valores da lista. Experimente por exemplo 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 cookies policy.