99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁大數(shù)據(jù)時代最詳細(xì)的matplotlib繪圖教程就在這里了!
最詳細(xì)的matplotlib繪圖教程就在這里了!
2020-08-07
收藏

matplotlib是我們經(jīng)常會用到的一款python繪圖庫,操作簡單,幾行代碼就能很輕松地畫一些或簡單或復(fù)雜地圖形,線圖、直方圖、功率譜、條形圖、錯誤圖、散點圖以及費(fèi)笛卡爾坐標(biāo)圖等都不在話下。今天小編就具體給大家介紹一下matplotlib繪圖教程。

一、首先來了解一下matplotlib

1.matplotlib是基于python語言的開源數(shù)據(jù)繪圖包。matplotlib的對象體系嚴(yán)謹(jǐn)而有趣,為我們提供了巨大的發(fā)揮空間。在熟悉了核心對象之后,我們可以輕易的定制圖像。matplotlib使用numpy進(jìn)行數(shù)組運(yùn)算,并調(diào)用一系列其他的python庫來實現(xiàn)硬件交互。

2.matplotlib安裝

pip install matplotlib

3.Matplotlib導(dǎo)入

import matplotlib.pyplot as plt#為方便簡介為plt

import numpy as np#畫圖過程中會使用numpy

import pandas as pd#畫圖過程中會使用pandas

二、matplotlib繪圖

1.柱形圖,散點圖,餅狀圖,折線圖


import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
%matplotlib inline

fig = plt.figure(figsize=(10,8))  #建立一個大小為10*8的畫板
ax1 = fig.add_subplot(331)  #在畫板上添加3*3個畫布,位置是第1個
ax2 = fig.add_subplot(3,3,2)
ax3 = fig.add_subplot(3,3,3)
ax4 = fig.add_subplot(334)
ax5 = fig.add_subplot(3,3,5)
ax6 = fig.add_subplot(3,3,6)
ax7 = fig.add_subplot(3,3,7)
ax8 = fig.add_subplot(3,3,8)
ax9 = fig.add_subplot(3,3,9)

ax1.plot(np.random.randn(10))
_ = ax2.scatter(np.random.randn(10),np.arange(10),color='r')  #作散點圖
ax3.hist(np.random.randn(20),bins=10,alpha=0.3)  #作柱形圖
ax4.bar(np.arange(10),np.random.randn(10))  #做直方圖
ax5.pie(np.random.randint(1,15,5),explode=[0,0,0.2,0,0])  #作餅形圖

x = np.arange(10)
y = np.random.randn(10)
ax6.plot(x,y,color='green')
ax6.bar(x,y,color='k')

data = DataFrame(np.random.randn(1000,10),
                 columns=['one','two','three','four','five','six','seven','eight','nine','ten'])
data2 = DataFrame(np.random.randint(0,20,(10,2)),columns=['a','b'])
data.plot(x='one',y='two',kind='scatter',ax=ax7)  #針對DataFrame的一些作圖
data2.plot(x='a',y='b',kind='bar',ax=ax8,color='red',legend=False)
data2.plot(x='a',y='b',kind='barh',color='m',ax=ax9)
#plt.tight_layout() #避免出現(xiàn)疊影
#plt.show()




2.蠟燭圖


import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.finance as mpf
from pandas import Series, DataFrame
from matplotlib.pylab import date2num
%matplotlib inline

plt.rcParams['figure.autolayout'] = True
plt.rcParams['figure.figsize'] = 25,6
plt.rcParams['grid.alpha'] = .4
plt.rcParams['axes.unicode_minus'] = False
plt.rcParams['font.sans-serif'] = ['SimHei']

fig, ax = plt.subplots(1,1,figsize=(12,5))

mpf.candlestick_ohlc(ax=ax,quotes=data2.values[::3],width=.002,colorup='red',colordown='green')
plt.xticks(data2.date[::25],data.date.map(lambda x:x[:5])[::25],rotation=0)
ax.twiny().plot(data3.Open)
plt.tight_layout();



3.熱圖


import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
%matplotlib inline


df = DataFrame(np.random.randn(10,10))
fig = plt.figure(figsize=(12,5))
ax = fig.add_subplot(111)
axim = ax.imshow(df.values,interpolation='nearest')#cmap=plt.cm.gray_r, #cmap用來顯示顏色,可以另行設(shè)置
plt.colorbar(axim)
plt.show()


以上就是小編今天跟大家分享的matplotlib繪圖的一些方法啦,希望對與大家使用matplotlib有所幫助。

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時表示是新驗證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }