莫烦Matplotlib可视化第二章基本使用代码学习

基本用法

import matplotlib.pyplot as plt
import numpy as np"""
2.1基本用法
"""
# x = np.linspace(-1,1,50)    #[-1,1]50个点
# #y = 2*x +1
#
# y = x**2
# plt.plot(x,y)   #注意:x,y顺序不能反
# plt.show()"""
2.2figure图像
"""# x = np.linspace(-3,3,50)
# y1 = 2*x +1
# y2 = x**2
# # plt.figure()    #一个figure对应一张图
# # plt.plot(x,y1)
#
# plt.figure(num=3,figsize=(8,5))
# #num可以改变这是第几个figure,不然默认顺序排列。figsize是设置输出的长宽
# plt.plot(x,y2)
# plt.plot(x,y1,color = 'red',linewidth=1.0,linestyle='--')
# #线条的颜色,粗细,线条格式
# plt.show()"""
2.3,2.4 坐标轴设置
"""# x = np.linspace(-3,3,50)
# y1 = 2*x +1
# y2 = x**2
# plt.figure(num=3,figsize=(8,5))
# plt.plot(x,y2)
# plt.plot(x,y1,color = 'red',linewidth=1.0,linestyle='--')
#
# plt.xlim((-1,2)) #设置坐标轴范围
# plt.ylim((-2,3))
#
# plt.xlabel('I am x')    #坐标轴描述
# plt.ylabel('I am y')
#
# #2.3
#
# new_ticks = np.linspace(-1,2,5)
# print(new_ticks)
# plt.xticks(new_ticks)   #替换x轴坐标
# plt.yticks([-2,-1.8,-1,1.22,3],
#            [r'$really\ bad$',r'$bad$',r'$normal$',r'$good$',r'$really\ good$'])  #替换y轴坐标为文字
# #r是正则,$是为了让字体变好看,在字体中空格可能不识别,需要\+空格 来得到空格#2.4# #gca = 'get current axis'
# ax = plt.gca()  #获得当前坐标轴
# ax.spines['right'].set_color('none')    #spines对应的是图表的边框,right就是右边框,set_color('none')就是使右边框消失
# ax.spines['top'].set_color('none')
# ax.xaxis.set_ticks_position('bottom')   #用下面(bottom)坐标轴代替x
# ax.yaxis.set_ticks_position('left')
# ax.spines['bottom'].set_position(('data',-1))   #把x轴绑定在y轴的-1位置
# ax.spines['left'].set_position(('data',0))
#
# plt.show()"""
2.5 Legend图例
"""# l1,=plt.plot(x,y2,label = 'up')
# #plt.plot其实是有返回值的,为了放入handles中必须l1+逗号
# l2,=plt.plot(x,y1,color = 'red',linewidth=1.0,linestyle='--',label = 'down')
# #plt.legend()    #打出来label和图例
# #个性的图例
# plt.legend(handles=[l1,l2], labels =['aaa','bbb'],loc = 'best')    #打出来label和图例
# # loc=best可以自动找数据比较少的地方,防止挡住数据
# plt.show()"""
2.6 Annotation标注
"""
#
# x = np.linspace(-3,3,50)
# y = 2*x +1
# plt.figure(num=1,figsize=(8,5))
# plt.plot(x,y)
# ax = plt.gca()
# ax.spines['right'].set_color('none')
# ax.spines['top'].set_color('none')
# ax.xaxis.set_ticks_position('bottom')
# ax.yaxis.set_ticks_position('left')
# ax.spines['bottom'].set_position(('data',0))
# ax.spines['left'].set_position(('data',0))
#
# x0 = 1
# y0 = 2*x0 + 1
# plt.scatter(x0,y0,s=50,color = 'b')  #展示(x0,y0)点 ,s = size
# plt.plot([x0,x0],[y0,0],'k--',lw = 2.5) #从[x0,x0]到[y0,0]画条直线,k=black,--是虚线,lw是粗细
#
# #method 1
# plt.annotate(r'$2x+1=%s$'%y0,xy=(x0,y0),xycoords = 'data',xytext=(+30,-30),textcoords='offset points',
#              fontsize=16,arrowprops=dict(arrowstyle='->',connectionstyle = 'arc3,rad = .2'))
# #r'$2x+1=%s$'%y0是指标注的文字,xy=(x0,y0)是指出这个点,xycoords以data值为基准,textcoords是指在xytext的位置上(x+30,y-30)进行描述
#
# #method 2
# plt.text(-3.7,3,r'$This\ is\ the\ some\ text.\mu\ \sigma_i\ \alpha_t$',fontdict={'size':16,'color':'r'})
# plt.show()"""
2.7 tick能见度
"""x = np.linspace(-3,3,50)
y = 0.1*xplt.figure()
plt.plot(x,y,linewidth = 10)
plt.ylim(-2,2)
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.spines['bottom'].set_position(('data',0))
ax.spines['left'].set_position(('data',0))for label in ax.get_xticklabels() + ax.get_yticklabels():label.set_fontsize(12)label.set_bbox(dict(facecolor= 'white',edgecolor='None',alpha = 0.7))  #标注颜色,标注背景颜色,alpha是透明度plt.show()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389415.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

vue.js python_使用Python和Vue.js自动化报告过程

vue.js pythonIf your organization does not have a data visualization solution like Tableau or PowerBI nor means to host a server to deploy open source solutions like Dash then you are probably stuck doing reports with Excel or exporting your notebooks.如果…

plsql中导入csvs_在命令行中使用sql分析csvs

plsql中导入csvsIf you are familiar with coding in SQL, there is a strong chance you do it in PgAdmin, MySQL, BigQuery, SQL Server, etc. But there are times you just want to use your SQL skills for quick analysis on a small/medium sized dataset.如果您熟悉SQ…

第十八篇 Linux环境下常用软件安装和使用指南

提醒:如果之后要安装virtualenvwrapper的话,可以直接跳到安装virtualenvwrapper的方法,而不需要先安装好virtualenv安装virtualenv和生成虚拟环境安装virtualenv:yum -y install python-virtualenv生成虚拟环境:先切换…

莫烦Matplotlib可视化第三章画图种类代码学习

3.1散点图 import matplotlib.pyplot as plt import numpy as npn 1024 X np.random.normal(0,1,n) Y np.random.normal(0,1,n) T np.arctan2(Y,X) #用于计算颜色plt.scatter(X,Y,s75,cT,alpha0.5)#alpha是透明度 #plt.scatter(np.arange(5),np.arange(5)) #一条线的散点…

计算机科学必读书籍_5篇关于数据科学家的产品分类必读文章

计算机科学必读书籍Product categorization/product classification is the organization of products into their respective departments or categories. As well, a large part of the process is the design of the product taxonomy as a whole.产品分类/产品分类是将产品…

es6解决回调地狱问题

本文摘抄自阮一峰老师的 http://es6.ruanyifeng.com/#docs/generator-async 异步 所谓"异步",简单说就是一个任务不是连续完成的,可以理解成该任务被人为分成两段,先执行第一段,然后转而执行其他任务,等做好…

交替最小二乘矩阵分解_使用交替最小二乘矩阵分解与pyspark建立推荐系统

交替最小二乘矩阵分解pyspark上的动手推荐系统 (Hands-on recommender system on pyspark) Recommender System is an information filtering tool that seeks to predict which product a user will like, and based on that, recommends a few products to the users. For ex…

莫烦Matplotlib可视化第四章多图合并显示代码学习

4.1Subplot多合一显示 import matplotlib.pyplot as plt import numpy as npplt.figure() """ 每个图占一个位置 """ # plt.subplot(2,2,1) #将画板分成两行两列,选取第一个位置,可以去掉逗号 # plt.plot([0,1],[0,1]) # # plt.su…

python 网页编程_通过Python编程检索网页

python 网页编程The internet and the World Wide Web (WWW), is probably the most prominent source of information today. Most of that information is retrievable through HTTP. HTTP was invented originally to share pages of hypertext (hence the name Hypertext T…

Python+Selenium自动化篇-5-获取页面信息

1.获取页面title title:获取当前页面的标题显示的字段from selenium import webdriver import time browser webdriver.Chrome() browser.get(https://www.baidu.com) #打印网页标题 print(browser.title) #输出内容:百度一下,你就知道 2.…

火种 ctf_分析我的火种数据

火种 ctfOriginally published at https://www.linkedin.com on March 27, 2020 (data up to date as of March 20, 2020).最初于 2020年3月27日 在 https://www.linkedin.com 上 发布 (数据截至2020年3月20日)。 Day 3 of social distancing.社会疏离的第三天。 As I sit on…

莫烦Matplotlib可视化第五章动画代码学习

5.1 Animation 动画 import numpy as np import matplotlib.pyplot as plt from matplotlib import animationfig,ax plt.subplots()x np.arange(0,2*np.pi,0.01) line, ax.plot(x,np.sin(x))def animate(i):line.set_ydata(np.sin(xi/10))return line,def init():line.set…

data studio_面向营销人员的Data Studio —报表指南

data studioIn this guide, we describe both the theoretical and practical sides of reporting with Google Data Studio. You can use this guide as a comprehensive cheat sheet in your everyday marketing.在本指南中,我们描述了使用Google Data Studio进行…

人流量统计系统介绍_统计介绍

人流量统计系统介绍Its very important to know about statistics . May you be a from a finance background, may you be data scientist or a data analyst, life is all about mathematics. As per the wiki definition “Statistics is the discipline that concerns the …

pyhive 连接 Hive 时错误

一、User: xx is not allowed to impersonate xxx 解决办法&#xff1a;修改 core-site.xml 文件&#xff0c;加入下面的内容后重启 hadoop。 <property><name>hadoop.proxyuser.xx.hosts</name><value>*</value> </property><property…

乐高ev3 读取外部数据_数据就是新乐高

乐高ev3 读取外部数据When I was a kid, I used to love playing with Lego. My brother and I built almost all kinds of stuff with Lego — animals, cars, houses, and even spaceships. As time went on, our creations became more ambitious and realistic. There were…

图像灰度化与二值化

图像灰度化 什么是图像灰度化&#xff1f; 图像灰度化并不是将单纯的图像变成灰色&#xff0c;而是将图片的BGR各通道以某种规律综合起来&#xff0c;使图片显示位灰色。 规律如下&#xff1a; 手动实现灰度化 首先我们采用手动灰度化的方式&#xff1a; 其思想就是&#…

分析citibike数据eda

数据科学 (Data Science) CitiBike is New York City’s famous bike rental company and the largest in the USA. CitiBike launched in May 2013 and has become an essential part of the transportation network. They make commute fun, efficient, and affordable — no…

jvm感知docker容器参数

docker中的jvm检测到的是宿主机的内存信息&#xff0c;它无法感知容器的资源上限&#xff0c;这样可能会导致意外的情况。 -m参数用于限制容器使用内存的大小&#xff0c;超过大小时会被OOMKilled。 -Xmx: 默认为物理内存的1/4。 4核CPU16G内存的宿主机 java 7 docker run -m …

Flask之flask-script 指定端口

简介 Flask-Scropt插件为在Flask里编写额外的脚本提供了支持。这包括运行一个开发服务器&#xff0c;一个定制的Python命令行&#xff0c;用于执行初始化数据库、定时任务和其他属于web应用之外的命令行任务的脚本。 安装 用命令pip和easy_install安装&#xff1a; pip install…