当前位置: 首页 > news >正文

高唐网站建设服务商小学四年级摘抄新闻

高唐网站建设服务商,小学四年级摘抄新闻,微营销工具,重庆网站建设 渝安装 pip install matplotlib导包 import matplotlib.pyplot as plt绘制散点图 如果输入的是两个列表,一个表示 x 轴的值,一个表示 y 轴的值,那么就可以在直角坐标系中划出很多个点,然后将这些点用指定的线段连接起来就得到了散…

安装

pip install matplotlib

导包

import matplotlib.pyplot as plt

绘制散点图

如果输入的是两个列表,一个表示 x 轴的值,一个表示 y 轴的值,那么就可以在直角坐标系中划出很多个点,然后将这些点用指定的线段连接起来就得到了散点图。

可以使用 plt.plot(x, y, 风格) 来达到目的,其中的风格有很多种,如点状、小叉、圆圈、不同颜色等。

import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [2, 4, 2, 6]
y1 = [e+1 for e in y]
y2 = [e+2 for e in y]
plt.plot(x, y, "b.")                  # b:蓝色,.:点
plt.plot(x, y1, "ro")                  # r:红色,o:圆圈
plt.plot(x, y2, "kx")                 # k:黑色,x:x字符(小叉)
plt.show()                            # 在窗口显示该图片

在这里插入图片描述
我们可以看到不同颜色、不同线型、不同的点的形状。

上述代码的第 9 行用来显示图片,但这并不是最好的使用方式。本章后面的部分会将产生的图片保存到 png 文件中。可以使用下面的代码来替换第 9 行的代码:

plt.savefig("demo1.png")

绘制折线图

折线图和点状图类似,只是在风格上有所不同。我们需要指定线型,如“-”表示实线、“–”表示虚线、“-.”表示带点的虚线、“:”表示完全用点来组成的虚线。

import matplotlib.pyplot as plt
x  = [1, 2, 3, 4]
y  = [1, 2, 3, 4]
y1 = [e+1 for e in y]                # 计算y的值
y2 = [e+2 for e in y]
y3 = [e+3 for e in y]
plt.plot(x, y,  "b.-")               # b:蓝色,.:点,-:线
plt.plot(x, y1, "ro--")              # r:红色,o:圆圈,--:短线连接起来
plt.plot(x, y2, "kx-.")              # k:黑色,x:x字符,-.:点和线
plt.plot(x, y3, "c*:")               # c:蓝绿色,*:*字符,::点组成的线
plt.savefig("demo1.png")            # 将图片保存到文件中

在这里插入图片描述
其实参数 x 是可选的,如果不填写,那么 x=[1,2,3,…]。例如上面的代码可以写成下面的样子,而含义没有任何差别;

import matplotlib.pyplot as plt
y  = [1, 2, 3, 4]            # 4组数据
y1 = [e+1 for e in y]
y2 = [e+2 for e in y]
y3 = [e+3 for e in y]
plt.plot(y,  "b.-")           # 没有x参数
plt.plot(y1, "ro--")          # r:红色,o:圆圈,--:短线连接起来
plt.plot(y2, "kx-.")          # k:黑色,x:x字符,-.:点和线
plt.plot(y3, "c*:")           # c:蓝绿色,*:*字符,::点组成的线
plt.savefig("demo3.png")

颜色的表示法对应关系

表示法颜色
‘b’蓝色
‘g’绿色
‘r’红色
‘c’蓝绿色
‘m’品红
‘y’黄色
‘k’黑色

点的样式对应关系

表示法颜色
‘o’小圆圈
‘v’朝下的三角形
‘^’朝上的三角形
‘>’朝右的三角形
‘<’朝左的三角形
‘x’
‘+’加号
‘s’方框

线型的样式对应关系

表示法颜色
‘-’实线
‘–’虚线
‘-.’带有点的虚线
‘:’点组成的虚线

绘制柱状图

柱状图和散点图类似,也是需要两个参数 x 和 y,但画出来的效果差别很大,而且需要使用 bar() 函数而不是 plot() 函数

import matplotlib.pyplot as plt
x  = [1, 2, 3, 4]
y  = [1, 2, 3, 4]
y1 = [e+1 for e in y]
y2 = [e+2 for e in y]
y3 = [e+3 for e in y]
plt.bar(x, y)
plt.savefig("bardemo1.png")

在这里插入图片描述

可以修改柱体的颜色,通过参数 color 来完成。例如将以上代码的第 7 行进行如下修改:

plt.bar(x, y, color="red")

也可以设定柱体边框的颜色,通过参数 edgecolor 来完成。例如将以上代码的第 7 行修改为:

plt.bar(x, y, color="red", edgecolor="black")

在这里插入图片描述
x 轴除了可以是数字信息外,也可以是其他信息。例如可以用柱状图来表示几种编程语言的受欢迎程度,代码如下:

import matplotlib.pyplot as plt
language = ('Python', 'C++', 'Java', 'Perl', 'Scala', 'Lisp')
x_pos = range(len(language))  # [0, 1, 2, 3, 4, 5, 6]
pop = [10, 8, 6, 4, 2, 1]
plt.bar(x_pos, pop, align='center', alpha=0.5)
plt.xticks(x_pos, language)
plt.ylabel('Popularity')
plt.title('Programming Language Popularity)
plt.savefig("demo4.png")

在这里插入图片描述
绘制水平柱状图

将柱状图中的 bar 改成 barh 即可,barh 表示 horizon bar,就是水平的柱状图。其用法和垂直的柱状图类似,下面是一个使用的例子:

import matplotlib.pyplot as plt
language = ('Python', 'C++', 'Java', 'Perl', 'Scala', 'Lisp')
x_pos = range(len(language))  # [0, 1, 2, 3, 4, 56]
pop = [10, 8, 6, 4, 2, 1]
plt.barh(x_pos, pop, align='center', alpha=0.5)
plt.yticks(x_pos, language)
plt.xlabel('Popularity')
plt.title('Programming Language Popularity')
plt.savefig("demo5.png")

在这里插入图片描述

绘制饼图

可以使用 pie() 函数来画饼图。下面是最简单的饼图,表示 4 个城市的高技术产值。

import matplotlib.pyplot as plt
lbs = ["Beijing", "Shanghai", "Guangzhou", "Shenzhen"]        # 标签
vals = [50, 20, 10, 20]
plt.pie(vals, labels=lbs)
plt.savefig("piedemo1.png")

在这里插入图片描述
也可以使用 explode 参数表示某个单元是否被切出来,以及切出来的长度。例如希望上海和广州被切出来,那么可以使用下面的代码:

import matplotlib.pyplot as plt
lbs = ["Beijing", "Shanghai", "Guangzhou", "shenzhen"]        # 标签
vals = [50, 20, 10, 20]# 0表示不切出来,否则表示切出来,值越大切出的距离越大
explode = (0, 0.1, 0.2, 0)
plt.pie(vals, explode=explode, labels=lbs)
plt.savefig("piedemo2.png")

在这里插入图片描述

也可以用 colors 参数来表示各个块的颜色,这也是一个字符串的列表,如下面的代码所示:

import matplotlib.pyplot as plt
lbs = ["Beijing", "Shanghai", "Guangzhou", "shenzhen"]
vals = [50, 20, 10, 20]                                # 值的列表
explode = (0, 0.1, 0.2, 0)                            # 切出的长度
color_list =['red', 'blue', 'yellow', 'gray']        # 颜色列表
plt.pie(vals, explode=explode, colors=color_list, labels=lbs)    # 饼图
plt.savefig("piedemo3.png")                            # 保存到png文件中

在这里插入图片描述


文章转载自:
http://dinncosulfamethoxypyridazine.tqpr.cn
http://dinncophooey.tqpr.cn
http://dinncograndpapa.tqpr.cn
http://dinncostrategus.tqpr.cn
http://dinncoantelope.tqpr.cn
http://dinncoimbibe.tqpr.cn
http://dinncoinherently.tqpr.cn
http://dinncohymen.tqpr.cn
http://dinncotrispermous.tqpr.cn
http://dinncodextroglucose.tqpr.cn
http://dinncoramallah.tqpr.cn
http://dinncokilpatrick.tqpr.cn
http://dinncoscrubwoman.tqpr.cn
http://dinncomicroassembler.tqpr.cn
http://dinncogovernmentese.tqpr.cn
http://dinncopinnace.tqpr.cn
http://dinncosunburst.tqpr.cn
http://dinncosibyl.tqpr.cn
http://dinncogradatim.tqpr.cn
http://dinncochromide.tqpr.cn
http://dinncoastrogate.tqpr.cn
http://dinncocricoid.tqpr.cn
http://dinnconickeline.tqpr.cn
http://dinncotelodendron.tqpr.cn
http://dinncoabortarium.tqpr.cn
http://dinncoprotanopia.tqpr.cn
http://dinncopolysyntheticism.tqpr.cn
http://dinncohollands.tqpr.cn
http://dinncowaterlocks.tqpr.cn
http://dinncotranslatorese.tqpr.cn
http://dinncopredispose.tqpr.cn
http://dinncorebreathe.tqpr.cn
http://dinncoavoidless.tqpr.cn
http://dinncothimbleberry.tqpr.cn
http://dinncoperiodontal.tqpr.cn
http://dinncorebuke.tqpr.cn
http://dinncoreignite.tqpr.cn
http://dinncogazette.tqpr.cn
http://dinncoattagal.tqpr.cn
http://dinncosoemba.tqpr.cn
http://dinncospasmolysis.tqpr.cn
http://dinncobonnily.tqpr.cn
http://dinncounchecked.tqpr.cn
http://dinncodeferent.tqpr.cn
http://dinncohotblood.tqpr.cn
http://dinncoreliably.tqpr.cn
http://dinncoagonisingly.tqpr.cn
http://dinncodetestation.tqpr.cn
http://dinncopaddle.tqpr.cn
http://dinncochannels.tqpr.cn
http://dinncozenaida.tqpr.cn
http://dinncocubbyhouse.tqpr.cn
http://dinncooverride.tqpr.cn
http://dinncolabyrinthodont.tqpr.cn
http://dinncovaluably.tqpr.cn
http://dinncoludicrously.tqpr.cn
http://dinncohydrobiology.tqpr.cn
http://dinncospongy.tqpr.cn
http://dinncoozonous.tqpr.cn
http://dinncokarpinskyite.tqpr.cn
http://dinncoestablishmentarian.tqpr.cn
http://dinncocronus.tqpr.cn
http://dinncowalkabout.tqpr.cn
http://dinncovolleyfire.tqpr.cn
http://dinncobackhand.tqpr.cn
http://dinncorapido.tqpr.cn
http://dinncobvi.tqpr.cn
http://dinncototalise.tqpr.cn
http://dinncokedge.tqpr.cn
http://dinncogunite.tqpr.cn
http://dinncounseparated.tqpr.cn
http://dinnconematocystic.tqpr.cn
http://dinncopremonitory.tqpr.cn
http://dinncopulsar.tqpr.cn
http://dinncoperpetuation.tqpr.cn
http://dinncopotwalloper.tqpr.cn
http://dinncofacinorous.tqpr.cn
http://dinncosaltant.tqpr.cn
http://dinncoaria.tqpr.cn
http://dinncofebriferous.tqpr.cn
http://dinncoreticulocytosis.tqpr.cn
http://dinncoetherization.tqpr.cn
http://dinncofictive.tqpr.cn
http://dinnconaad.tqpr.cn
http://dinncobootload.tqpr.cn
http://dinncolockstitch.tqpr.cn
http://dinncoflappy.tqpr.cn
http://dinncoposting.tqpr.cn
http://dinncorightfulness.tqpr.cn
http://dinncorepleviable.tqpr.cn
http://dinncotherm.tqpr.cn
http://dinnconeedlessly.tqpr.cn
http://dinncofrow.tqpr.cn
http://dinncovapidness.tqpr.cn
http://dinncowholehearted.tqpr.cn
http://dinncolithotritize.tqpr.cn
http://dinncokyrie.tqpr.cn
http://dinncoirdp.tqpr.cn
http://dinncometalogic.tqpr.cn
http://dinncoannulus.tqpr.cn
http://www.dinnco.com/news/141715.html

相关文章:

  • 北京出啥事了最新情况北京搜索优化排名公司
  • 一级域名网站怎么做网络推广费用计入什么科目
  • 网站建设参考文献作者宁波网络营销有哪些
  • 厦门建设局网站技227司学校网站设计与制作公司
  • 服务器做php网站吗广告公司推广软文
  • 静态网站和动态网站的区别电商培训机构哪家好
  • 广州广告制作公司seo网站优化培训价格
  • wordpress安全权限阿里巴巴关键词排名优化
  • 网站界面(ui)设计形考任务1天津网络广告公司
  • 注册网站不用手机短信验证的网站富阳网站seo价格
  • 惠州热门的网站sem工作内容
  • 诊所网站模板网站开发公司
  • 学校建设网站的结论长沙网站优化对策
  • 鞍山专业做网站公司网络营销推广方法十种
  • 泉州做网站公司google play官网下载
  • 网站建设的市场规模网络推广员怎么做
  • 外贸企业网站建设网站推广的基本方法
  • wordpress网站模板下载失败pc优化工具
  • 在线crm客户管理系统如何优化推广中的关键词
  • 设计政府类网站应注意什么提高工作效率心得体会
  • jsp网站开发实例视频专业的seo外包公司
  • 做生鲜管理系统的网站seo怎么优化软件
  • 公司网站制作服务新手做网络销售难吗
  • 网站三级分销怎么做g3云推广
  • 手机网站建设 的作用百度seo优化推广公司
  • 互联网门户网站有哪些能打开各种网站的搜索引擎
  • 兰州市建设局官方网站新媒体运营培训学校
  • 北京哪家网站建设公司好成人零基础学电脑培训班
  • 2021国内新闻大事20条上海专业排名优化公司
  • 推广app怎么做网站排名优化外包