python导入绘图库的代码

python导入绘图库的代码,第1张

1.导入绘图库importmatplotlib.pyplotaspltimportn...

2.创建画板figure=plt.figure(figsize=(10,10))

3.创建子图subplot/Axes,生成2行1列的子图# 第一行第一列绘制sin图形,...

4.准备数据

不是呀,python有个例子

"""turtledemo.two_canvases

Use TurtleScreen and RawTurtle to draw on two

distinct canvases in a separate windows. The

new window must be separately closed in

addition to pressing the STOP button.

"""

from turtle import TurtleScreen, RawTurtle, TK

def main():

    root = TK.Tk()

    cv1 = TK.Canvas(root, width=300, height=200, bg="#ddffff")

    cv2 = TK.Canvas(root, width=300, height=200, bg="#ffeeee")

    cv1.pack()

    cv2.pack()

    s1 = TurtleScreen(cv1)

    s1.bgcolor(0.85, 0.85, 1)

    s2 = TurtleScreen(cv2)

    s2.bgcolor(1, 0.85, 0.85)

    p = RawTurtle(s1)

    q = RawTurtle(s2)

    p.color("red", (1, 0.85, 0.85))

    p.width(3)

    q.color("blue", (0.85, 0.85, 1))

    q.width(3)

    for t in p,q:

        t.shape("turtle")

        t.lt(36)

    q.lt(180)

    for t in p, q:

        t.begin_fill()

    for i in range(5):

        for t in p, q:

            t.fd(50)

            t.lt(72)

    for t in p,q:

        t.end_fill()

        t.lt(54)

        t.pu()

        t.bk(50)

    return "EVENTLOOP"

if __name__ == '__main__':

    main()

    TK.mainloop()  # keep window open until user closes it

开两个画板的

#!/usr/bin/env python

# -*- coding: utf-8 -*-

import sys

from random import randint, seed

import pygame

from pygame.locals import *

SCREEN_X = 640

SCREEN_Y = 480

pygame.init()

def convert_strs_to_color(color_list):

return Color(int(color_list[0]), int(color_list[1]), int(color_list[2]))

//画圆方法

def draw_circle(surface, color):

radius = randint(10, 100)

pos = (randint(radius, SCREEN_X-radius), randint(radius, SCREEN_Y-radius))

pygame.draw.circle(surface, color, pos, radius, 1)

//画长方形方法

def draw_rectangle(surface, color):

height = randint(10, 100)

width = randint(20, 250)

left = randint(0, SCREEN_X-width)

top = randint(0, SCREEN_Y-height)

pygame.draw.rect(surface, color, (left, top, width, height), 1)

//画线方法

def draw_line(surface, color):

start_pos = (randint(0, SCREEN_X), randint(0, SCREEN_Y))

while True:

end_pos = (randint(0, SCREEN_X), randint(0, SCREEN_Y))

# make sure they are not on same spot

if end_pos != start_pos:

break

填充区域

Surface.fill方法可以用一种颜色填充一个矩形区域。比如

surface.fill((255,0,0), (100, 200, 100, 100))

第一个参数指定要填充的颜色,第二个参数指定填充的矩形区域。如果没有给定第二个参数,整个Surface会被填充。第二个参数会限制备填充的区域。这个函数会返回受影响的Surface区域。

http://534994635.blog.163.com/blog/static/483763592010386487676/


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/11539144.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-16
下一篇2023-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存