最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python使用matplotlib和pandas實(shí)現(xiàn)的畫(huà)圖操作【經(jīng)典示例】

 更新時(shí)間:2018年06月13日 11:30:39   作者:旭旭_哥  
這篇文章主要介紹了Python使用matplotlib和pandas實(shí)現(xiàn)的畫(huà)圖操作,結(jié)合實(shí)例形式分析了Python基于matplotlib和pandas的數(shù)值運(yùn)算與圖形顯示操作相關(guān)實(shí)現(xiàn)技巧,并對(duì)部分代碼的圖形顯示進(jìn)行了顯示效果測(cè)試,需要的朋友可以參考下

本文實(shí)例講述了Python使用matplotlib和pandas實(shí)現(xiàn)的畫(huà)圖操作。分享給大家供大家參考,具體如下:

畫(huà)圖在工作再所難免,尤其在做數(shù)據(jù)探索時(shí)候,下面總結(jié)了一些關(guān)于python畫(huà)圖的例子

#encoding:utf-8
'''''
Created on 2015年9月11日
@author: ZHOUMEIXU204
'''
# pylab 是 matplotlib 面向?qū)ο罄L圖庫(kù)的一個(gè)接口。它的語(yǔ)法和 Matlab 十分相近
import pandas as pd
#from ggplot import *
import numpy as np
import matplotlib.pyplot as plt
df=pd.DataFrame(np.random.randn(1000,4),columns=list('ABCD'))
df=df.cumsum()
print(plt.figure())
print(df.plot())
print(plt.show())
# print(ggplot(df,aes(x='A',y='B'))+geom_point())

運(yùn)行效果:

# 畫(huà)簡(jiǎn)單的圖形
from pylab import *
x=np.linspace(-np.pi,np.pi,256,endpoint=True)
c,s=np.cos(x),np.sin(x)
plot(x,c, color="blue", linewidth=2.5, linestyle="-", label="cosine") #label用于標(biāo)簽顯示問(wèn)題
plot(x,s,color="red", linewidth=2.5, linestyle="-", label="sine")
show()

運(yùn)行效果:

#散點(diǎn)圖
from pylab import *
n = 1024
X = np.random.normal(0,1,n)
Y = np.random.normal(0,1,n)
scatter(X,Y)
show()

運(yùn)行效果:

#條形圖
from pylab import *
n = 12
X = np.arange(n)
Y1 = (1-X/float(n)) * np.random.uniform(0.5,1.0,n)
Y2 = (1-X/float(n)) * np.random.uniform(0.5,1.0,n)
bar(X, +Y1, facecolor='#9999ff', edgecolor='white')
bar(X, -Y2, facecolor='#ff9999', edgecolor='white')
for x,y in zip(X,Y1):
 text(x+0.4, y+0.05, '%.2f' % y, ha='center', va= 'bottom')
ylim(-1.25,+1.25)
show()

運(yùn)行效果:

#餅圖
from pylab import *
n = 20
Z = np.random.uniform(0,1,n)
pie(Z), show()

運(yùn)行效果:

#畫(huà)三維圖
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from pylab import *
fig=figure()
ax=Axes3D(fig)
x=np.arange(-4,4,0.1)
y=np.arange(-4,4,0.1)
x,y=np.meshgrid(x,y)
R=np.sqrt(x**2+y**2)
z=np.sin(R)
ax.plot_surface(x,y,z,rstride=1,cstride=1,cmap='hot')
show()

運(yùn)行效果:

#用于圖像顯示的問(wèn)題
import matplotlib.pyplot as plt
import pandas as pd
weights_dataframe=pd.DataFrame()
plt.figure()
plt.plot(weights_dataframe.weights_ij,weights_dataframe.weights_x1,label='weights_x1')
plt.plot(weights_dataframe.weights_ij,weights_dataframe.weights_x0,label='weights_x0')
plt.plot(weights_dataframe.weights_ij,weights_dataframe.weights_x2,label='weights_x2')
plt.legend(loc='upper right') #用于標(biāo)簽顯示問(wèn)題
plt.xlabel(u"迭代次數(shù)", fontproperties='SimHei')
plt.ylabel(u"參數(shù)變化", fontproperties='SimHei')
plt.title(u"迭代次數(shù)顯示", fontproperties='SimHei') #fontproperties='SimHei' 用于可以顯示中文
plt.show()
import matplotlib.pyplot as plt
from numpy.random import random
colors = ['b', 'c', 'y', 'm', 'r']
lo = plt.scatter(random(10), random(10), marker='x', color=colors[0])
ll = plt.scatter(random(10), random(10), marker='o', color=colors[0])
l = plt.scatter(random(10), random(10), marker='o', color=colors[1])
a = plt.scatter(random(10), random(10), marker='o', color=colors[2])
h = plt.scatter(random(10), random(10), marker='o', color=colors[3])
hh = plt.scatter(random(10), random(10), marker='o', color=colors[4])
ho = plt.scatter(random(10), random(10), marker='x', color=colors[4])
plt.legend((lo, ll, l, a, h, hh, ho),
   ('Low Outlier', 'LoLo', 'Lo', 'Average', 'Hi', 'HiHi', 'High Outlier'),
   scatterpoints=1,
   loc='lower left',
   ncol=3,
   fontsize=8)
plt.show()

#pandas中畫(huà)圖
#畫(huà)累和圖
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
ts=pd.Series(np.random.randn(1000),index=pd.date_range('1/1/2000',periods=1000))
ts=ts.cumsum()
ts.plot()
plt.show()
df=pd.DataFrame(np.random.randn(1000,4),index=ts.index,columns=list('ABCD'))
df=df.cumsum()
df.plot()
plt.show()

import pandas as pd
import  numpy  as  np
import matplotlib.pyplot as plt
#畫(huà)柱狀圖
df2 = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
df2.plot(kind='bar') #分開(kāi)并列線束
df2.plot(kind='bar', stacked=True) #四個(gè)在同一個(gè)里面顯示 百分比的形式
df2.plot(kind='barh', stacked=True)#縱向顯示
plt.show()
df4=pd.DataFrame({'a':np.random.randn(1000)+1,'b':np.random.randn(1000),'c':np.random.randn(1000)-1},columns=list('abc'))
df4.plot(kind='hist', alpha=0.5)
df4.plot(kind='hist', stacked=True, bins=20)
df4['a'].plot(kind='hist', orientation='horizontal',cumulative=True) #cumulative是按順序排序,加上這個(gè)
plt.show()
#Area Plot
df = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
df.plot(kind='area')
df.plot(kind='area',stacked=False)
plt.show()
#散點(diǎn)圖
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.DataFrame(np.random.rand(50, 4), columns=['a', 'b', 'c', 'd'])
df.plot(kind='scatter', x='a', y='b')
df.plot(kind='scatter', x='a', y='b',color='DarkBlue', label='Group 1')
#餅圖
df = pd.DataFrame(3 * np.random.rand(4, 2), index=['a', 'b', 'c', 'd'], columns=['x', 'y'])
df.plot(kind='pie', subplots=True, figsize=(8, 4))
df.plot(kind='pie', subplots=True,autopct='%.2f',figsize=(8, 4)) #顯示百分比
plt.show()
#畫(huà)矩陣散點(diǎn)圖
df = pd.DataFrame(np.random.randn(1000, 4), columns=['a', 'b', 'c', 'd'])
pd.scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal='kde')
plt.show()

實(shí)際我個(gè)人喜歡用R語(yǔ)言畫(huà)圖,python畫(huà)圖也有g(shù)gplot類似的包

更多關(guān)于Python相關(guān)內(nèi)容可查看本站專題:《Python數(shù)學(xué)運(yùn)算技巧總結(jié)》、《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門(mén)與進(jìn)階經(jīng)典教程

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Python中sorted()函數(shù)的強(qiáng)大排序技術(shù)實(shí)例探索

    Python中sorted()函數(shù)的強(qiáng)大排序技術(shù)實(shí)例探索

    排序在編程中是一個(gè)基本且重要的操作,而Python的sorted()函數(shù)則為我們提供了強(qiáng)大的排序能力,在本篇文章中,我們將深入研究不同排序算法、sorted()?函數(shù)的靈活性,以及各種排序場(chǎng)景下的最佳實(shí)踐
    2024-01-01
  • OpenCV立體圖像深度圖Depth Map基礎(chǔ)

    OpenCV立體圖像深度圖Depth Map基礎(chǔ)

    這篇文章主要為大家介紹了OpenCV立體圖像深度圖Depth Map基礎(chǔ)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-05-05
  • Python函數(shù)的作用域及內(nèi)置函數(shù)詳解

    Python函數(shù)的作用域及內(nèi)置函數(shù)詳解

    這篇文章主要介紹了python函數(shù)的作用域及內(nèi)置函數(shù)詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2021-09-09
  • 老生常談Python進(jìn)階之裝飾器

    老生常談Python進(jìn)階之裝飾器

    下面小編就為大家?guī)?lái)一篇老生常談Python進(jìn)階之裝飾器。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-05-05
  • python 非線性規(guī)劃方式(scipy.optimize.minimize)

    python 非線性規(guī)劃方式(scipy.optimize.minimize)

    今天小編就為大家分享一篇python 非線性規(guī)劃方式(scipy.optimize.minimize),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-02-02
  • pymongo實(shí)現(xiàn)控制mongodb中數(shù)字字段做加法的方法

    pymongo實(shí)現(xiàn)控制mongodb中數(shù)字字段做加法的方法

    這篇文章主要介紹了pymongo實(shí)現(xiàn)控制mongodb中數(shù)字字段做加法的方法,涉及Python使用pymongo模塊操作mongodb數(shù)據(jù)庫(kù)字段的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-03-03
  • python中l(wèi)eastsq函數(shù)的使用方法

    python中l(wèi)eastsq函數(shù)的使用方法

    這篇文章主要介紹了python中l(wèi)eastsq函數(shù)的使用方法,leastsq作用是最小化一組方程的平方和,下面文章舉例說(shuō)明詳細(xì)內(nèi)容,具有一的參考價(jià)值,需要的小伙伴可以參考一下
    2022-03-03
  • Flask框架Jinjia模板常用語(yǔ)法總結(jié)

    Flask框架Jinjia模板常用語(yǔ)法總結(jié)

    這篇文章主要介紹了Flask框架Jinjia模板常用語(yǔ)法,結(jié)合實(shí)例形式總結(jié)分析了Jinjia模板的變量、賦值、流程控制、函數(shù)、塊、宏等基本使用方法,需要的朋友可以參考下
    2018-07-07
  • 詳解使用PyInstaller將Pygame庫(kù)編寫(xiě)的小游戲程序打包為exe文件

    詳解使用PyInstaller將Pygame庫(kù)編寫(xiě)的小游戲程序打包為exe文件

    這篇文章主要介紹了詳解使用PyInstaller將Pygame庫(kù)編寫(xiě)的小游戲程序打包為exe文件,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • 更新pip3與pyttsx3文字語(yǔ)音轉(zhuǎn)換的實(shí)現(xiàn)方法

    更新pip3與pyttsx3文字語(yǔ)音轉(zhuǎn)換的實(shí)現(xiàn)方法

    今天小編就為大家分享一篇更新pip3與pyttsx3文字語(yǔ)音轉(zhuǎn)換的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-08-08

最新評(píng)論

浦江县| 垦利县| 河西区| 楚雄市| 斗六市| 昌吉市| 库车县| 大渡口区| 台州市| 彩票| 曲松县| 峨眉山市| 丰城市| 油尖旺区| 彝良县| 肥西县| 饶阳县| 高唐县| 渭南市| 合肥市| 浠水县| 东乌珠穆沁旗| 乌苏市| 高淳县| 罗江县| 克拉玛依市| 和顺县| 鄂托克旗| 宝应县| 武平县| 宝丰县| 桂林市| 沅陵县| 汕尾市| 镇沅| 革吉县| 抚宁县| 聂荣县| 贵港市| 云霄县| 衡水市|