莫煩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.pswp.cn/news/389415.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389415.shtml
英文地址,請注明出處:http://en.pswp.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…