当前位置:首页 » 编程语言 » 画图并保存Python

画图并保存Python

发布时间: 2022-06-11 04:35:22

❶ 怎样用python画图

思路:

1. 确定好需要画的图。

2. 创建一个画布,用来画你需要的图。

(1)画布大小,可以使用默认大小,也可以自定义画布大小。

(2)画布背景色bgcolor()。

(3)确定起点位置。

3. 画笔的设置。

(1)画笔的大小,颜色。

(2)画笔运行属性。

二、定义画布参数

importturtleast
t.screensize(width=None,heigh=None,bg=None)#以像素为单位,参数分别为画布的宽,高,背景色
t.screensize()#返回默认大小(400,300)
t.Screen()#也是表示默认画布大小,注意S大写
t.setup(w=0.5,h=0.75,startx=None,starty=None)#w,h为整数是表示像素,为小数时表示占据电脑屏幕的比例
#startx,starty坐标表示矩形窗口左上角顶点的位置,默认为屏幕中心位置

三、定义画笔

1、画笔的状态

在画布上默认有一个坐标原点为画布中心的坐标轴,坐标原点上有一只面朝x轴正方向小乌龟。这里我们描述小乌龟时使用了两个词语:坐标原点(位置),面朝x轴正方向(方向),turtle绘图中,就是使用位置方向描述小乌龟(画笔)的状态。

2、画笔的属性

画笔(画笔的属性,颜色、画线的宽度)

(1)turtle.pensize():设置画笔的宽度;

(2)turtle.pencolor():没有参数传入,返回当前画笔颜色,传入参数设置画笔颜色,可以是字符串如"green","red",也可以是RGB 3元组;

>>>pencolor('brown')
>>>tup=(0.2,0.8,0.55)
>>>pencolor(tup)
>>>pencolor()
'#33cc8c'

(3)turtle.speed(speed):设置画笔移动速度,画笔绘制的速度范围[0,10]整数,数字越大越快。

相关推荐:《Python入门教程》

3、绘图命令

操纵海龟绘图有着许多的命令,这些命令可以划分为3种:一种为运动命令,一种为画笔控制命令,还有一种是全局控制命令。

(1)画笔运动命令:

(3)全局控制命令:

四、命令详解

turtle.circle(radius,extent=None,steps=None)

描述:以给定半径画圆

参数:

radius(半径);半径为正(负),表示圆心在画笔的左边(右边)画圆;

extent(弧度) (optional);

steps (optional) (做半径为radius的圆的内切正多边形,多边形边数为steps);

举例:

circle(50)#整圆;
circle(50,steps=3)#三角形;
circle(120,180)#半圆

五、绘图举例

(1)菱形太阳花

importturtleast#turtle库是python的内部库,直接import使用即可
defdraw_diamond(turt):
foriinrange(1,3):
turt.forward(100)#向前走100步

希望我的回答对你有帮助

❷ python用turtle作图能保存吗

用turtle画完图后使用如下代码保存

ts = turtle.getscreen()

ts.getcanvas().postscript(file="pic.eps")
然后可以再用ps等软件来转换为常用的jpg等格式

❸ python中tkinter怎么将画布保存为图像

可以通过Canvas的postscript方法,将画布内容封装成 PostScript 格式,然后再通过其它图片操作转为你需要的图片格式

❹ python画图

matplotlib就可以,看他示例文件里动画那个文件夹

❺ Python画图

python作为一门胶水语言,很多功能是靠调用其他语言的库来实现的。
像你这种需求,最好是用C/C++对画图操作进行封装,然后Python调用动态链接库

❻ Python语言画图

1)首先Python画图与WING IDE无关,最简单的是使用Tkinter画图
2)画出单词有很多方法,最笨的是用划线方式一笔一笔的画。其次是直接输出文本,但意义不大。另外一种方法是调用图片,你可以在图片上任意画好东西后显示出来。
3)代码示例:(这个例子就画了个简单的字母P)
from Tkinter import *
root=Tk()
root.title('Drawing Example')
canvas=Canvas(root,width=200,height=160,bg='white')
canvas.create_line(10,10,100,70)
canvas.create_line(10,10,40,10)
canvas.create_line(40,10,40,40)
canvas.create_line(10,40,40,40)
canvas.pack()
root.mainloop()

❼ Python 画图存储(savefig)

你可以安装python的第三方应用chartdirector,如下面用python代码生成多个曲线的png图形,并可以自定义layout.


#!/usr/bin/python
from pychartdir import *

# The data for the line chart
data0 = [42, 49, 33, 38, 51, 46, 29, 41, 44, 57, 59, 52, 37, 34, 51, 56, 56, 60, 70,
76, 63, 67, 75, 64, 51]
data1 = [50, 55, 47, 34, 42, 49, 63, 62, 73, 59, 56, 50, 64, 60, 67, 67, 58, 59, 73,
77, 84, 82, 80, 84, 98]
data2 = [36, 28, 25, 33, 38, 20, 22, 30, 25, 33, 30, 24, 28, 15, 21, 26, 46, 42, 48,
45, 43, 52, 64, 60, 70]

# The labels for the line chart
labels = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"]

# Create an XYChart object of size 600 x 300 pixels, with a light blue (EEEEFF)
# background, black border, 1 pxiel 3D border effect and rounded corners
c = XYChart(600, 300, 0xeeeeff, 0x000000, 1)
c.setRoundedFrame()

# Set the plotarea at (55, 58) and of size 520 x 195 pixels, with white background.
# Turn on both horizontal and vertical grid lines with light grey color (0xcccccc)
c.setPlotArea(55, 58, 520, 195, 0xffffff, -1, -1, 0xcccccc, 0xcccccc)

# Add a legend box at (50, 30) (top of the chart) with horizontal layout. Use 9 pts
# Arial Bold font. Set the background and border color to Transparent.
c.addLegend(50, 30, 0, "arialbd.ttf", 9).setBackground(Transparent)

# Add a title box to the chart using 15 pts Times Bold Italic font, on a light blue
# (CCCCFF) background with glass effect. white (0xffffff) on a dark red (0x800000)
# background, with a 1 pixel 3D border.
c.addTitle("Application Server Throughput", "timesbi.ttf", 15).setBackground(
0xccccff, 0x000000, glassEffect())

# Add a title to the y axis
c.yAxis().setTitle("MBytes per hour")

# Set the labels on the x axis.
c.xAxis().setLabels(labels)

# Display 1 out of 3 labels on the x-axis.
c.xAxis().setLabelStep(3)

# Add a title to the x axis
c.xAxis().setTitle("Jun 12, 2006")

# Add a line layer to the chart
layer = c.addLineLayer2()

# Set the default line width to 2 pixels
layer.setLineWidth(2)

# Add the three data sets to the line layer. For demo purpose, we use a dash line
# color for the last line
layer.addDataSet(data0, 0xff0000, "Server #1")
layer.addDataSet(data1, 0x008800, "Server #2")
layer.addDataSet(data2, c.dashLineColor(0x3333ff, DashLine), "Server #3")

# Output the chart
c.makeChart("multiline.png")

❽ 怎么用python绘图

你可以使用numpy和matplotlab这两个库来实现的你功能。

你的图可以参考:

http://matplotlib.org/examples/pylab_examples/histogram_percent_demo.html

importmatplotlib
fromnumpy.randomimportrandn
importmatplotlib.pyplotasplt
frommatplotlib.tickerimportFuncFormatter

defto_percent(y,position):
#Ignorethepassedinposition.
#ticklocations.
s=str(100*y)

#
ifmatplotlib.rcParams['text.usetex']==True:
returns+r'$\%$'
else:
returns+'%'

x=randn(5000)

#Makeanormedhistogram.It'llbemultipliedby100later.
plt.hist(x,bins=50,normed=True)

#_percent.Thismultipliesallthe
#defaultlabelsby100,makingthemallpercentages
formatter=FuncFormatter(to_percent)

#Settheformatter
plt.gca().yaxis.set_major_formatter(formatter)

plt.show()

最主要的就是x轴和y轴的处理,我按照对数算了一下你提供的数据,好像和这个图效果不一样。


如果解决了您的问题请采纳!
如果未解决请继续追问

❾ 关于Python的画图的东西。

画正方形

importturtle
importtime
#定义绘制时画笔的颜色
turtle.color("purple")
#定义绘制时画笔的线条的宽度
turtle.size(5)
#定义绘图的速度
turtle.speed(10)
#以0,0为起点进行绘制
turtle.goto(0,0)
#绘出正方形的四条边
foriinrange(4):
turtle.forward(100)
turtle.right(90)
#画笔移动到点(-150,-120)时不绘图
turtle.up()
turtle.goto(-150,-120)
#再次定义画笔颜色
turtle.color("red")
#在(-150,-120)点上打印"Done"
turtle.write("Done")
time.sleep(3)

❿ 为什么用python保存图片为0K

保存的方式有两种。
1、使用matplotlib画图保存方法:首先,import头文件如下:import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib.pyplot import plot,savefig画图:fig, ax = plt.subplots(figsize=(12, 12)) ax.imshow(im, aspect='equal') #im是要显示的图像。保存图片:savefig("D:/1.jpg")展示图片:plt.show()2、turtle生成图片保存代码示例如下:from Tkinter import * from turtle import * import turtle forward(100) ts = turtle.getscreen() ts.getcanvas().postscript(file="ck.eps") #.eps文件即postscript脚本以上就是python画图后如何保存的详细内容。

热点内容
魔兽世界自动钓鱼脚本 发布:2024-05-19 06:43:07 浏览:494
cbs加密 发布:2024-05-19 06:29:56 浏览:200
ssis存储过程 发布:2024-05-19 06:21:31 浏览:630
怎样删除小视频文件夹 发布:2024-05-19 05:49:29 浏览:589
开启php短标签 发布:2024-05-19 05:44:12 浏览:473
android各国语言 发布:2024-05-19 05:42:54 浏览:247
微信什么资料都没怎么找回密码 发布:2024-05-19 05:35:34 浏览:907
填志愿密码是什么 发布:2024-05-19 05:30:23 浏览:318
城堡争霸自动掠夺脚本 发布:2024-05-19 05:22:06 浏览:204
asp编程工具 发布:2024-05-19 05:20:36 浏览:143