国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
要想成為一名月入幾萬的數(shù)據(jù)分析師,繪制圖表是必會(huì)的!實(shí)例教程


1.折線圖

在繪制折線圖時(shí),如果你的數(shù)據(jù)很小,圖表的線條有點(diǎn)折,當(dāng)你數(shù)據(jù)集比較大時(shí)候,比如超過100個(gè)點(diǎn),則會(huì)呈現(xiàn)相對平滑的曲線。

在這里,我們使用三個(gè)plt.plot繪制了,不同斜率(1,2和3)的三條線。

import numpy as np

import matplotlib.pyplot as plt

cc= np.linspace(0,2,100)

plt.rcParams['font.sans-serif'] = ['SimHei']

plt.plot(cc,cc,label='linear')

plt.plot(cc,cc**2,label='兩倍')

plt.plot(cc,cc**3,label='三倍')

plt.xlabel('x label')

plt.ylabel('y label')

plt.title('折線圖')

plt.legend()

plt.show()

cc = np.linspace(0,2,100)

plt.plot(cc,cc,label ='linear')

plt.plot(cc,cc ** 2,label ='quadratic')

plt.plot(cc,cc ** 3,label ='cubic')

plt.xlabel('x label')

plt.ylabel('y label')

結(jié)果顯示,如下:




注意為了顯示中文,我們plt.rcParams屬性設(shè)置了中文字體,不然不能正確顯示中文title的。



3.直方圖

直方圖也是一種常用的簡單圖表,本例中我們在同一張圖片中繪制兩個(gè)概率直方圖。

import numpy as np

import matplotlib.pyplot as plt

np.random.seed(19680801)

mu1, sigma1 = 100, 15

mu2, sigma2 = 80, 15

x1 = mu1 + sigma1 * np.random.randn(10000)

x2 = mu2 + sigma2 * np.random.randn(10000)

n1, bins1, patches1 = plt.hist(x1, 50, density=True, facecolor='g', alpha=1)

n2, bins2, patches2 = plt.hist(x2, 50, density=True, facecolor='r', alpha=0.2)

plt.rcParams['font.sans-serif'] = ['SimHei']

plt.xlabel('智商')

plt.ylabel('置信度')

plt.title('IQ直方圖')

plt.text(110, .025, r'$mu=100, sigma=15$')

plt.text(50, .025, r'$mu=80, sigma=15$')

# 設(shè)置坐標(biāo)范圍

plt.axis([40, 160, 0, 0.03])

plt.grid(True)

plt.show()

顯示效果為:


4.條形圖

我們要介紹的第四種,圖表類型是條形圖,我們這兒引入稍微比較復(fù)雜的條形圖。

4.1平行條形圖

此例中,我們引入三組(a,b,c)5個(gè)隨機(jī)數(shù)(0~1),并用條形圖打印出來,做比較

import numpy as np

import matplotlib.pyplot as plt

size = 5

a = np.random.random(size)

b = np.random.random(size)

c = np.random.random(size)

x = np.arange(size)

total_width, n = 0.8, 3

width = total_width / n

# redraw the coordinates of x

x = x - (total_width - width) / 2

# here is the offset

plt.bar(x, a, width=width, label='a')

plt.bar(x + width, b, width=width, label='b')

plt.bar(x + 2 * width, c, width=width, label='c')

plt.legend()

plt.show()

顯示效果為:


4.2堆積條形圖

數(shù)據(jù)同上,不過條形plot的時(shí)候,用的相互的值大小差異(水平方向),而不是條柱平行對比。

import numpy as np

import matplotlib.pyplot as plt

size = 5

a = np.random.random(size)

b = np.random.random(size)

c = np.random.random(size)

x = np.arange(size)

plt.bar(x, a, width=0.5, label='a',fc='r')

plt.bar(x, b, bottom=a, width=0.5, label='b', fc='g')

plt.bar(x, c, bottom=a+b, width=0.5, label='c', fc='b')

plt.ylim(0, 2.5)

plt.legend()

plt.grid(True)

plt.show()

顯示效果為:




5.2嵌套餅圖

import numpy as np

import matplotlib.pyplot as plt

size = 0.3

vals = np.array([[60., 32.], [37., 40.], [29., 10.]])

cmap = plt.get_cmap('tab20c')

outer_colors = cmap(np.arange(3)*4)

inner_colors = cmap(np.array([1, 2, 5, 6, 9, 10]))

print(vals.sum(axis=1))

# [92. 77. 39.]

plt.pie(vals.sum(axis=1), radius=1, colors=outer_colors,

wedgeprops=dict(width=size, edgecolor='w'))

print(vals.flatten())

# [60. 32. 37. 40. 29. 10.]

plt.pie(vals.flatten(), radius=1-size, colors=inner_colors,

wedgeprops=dict(width=size, edgecolor='w'))

# equal makes it a perfect circle

plt.axis('equal')

plt.show()

顯示效果為:


5.3極軸餅圖

極軸餅圖是一種非??岬膱D表,讓我們看他的源碼:

import numpy as np

import matplotlib.pyplot as plt

np.random.seed(19680801)

N = 10

theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False)

radii = 10 * np.random.rand(N)

width = np.pi / 4 * np.random.rand(N)

ax = plt.subplot(111, projection='polar')

bars = ax.bar(theta, radii, width=width, bottom=0.0)

for r, bar in zip(radii, bars):

bar.set_facecolor(plt.cm.viridis(r / 10.))

bar.set_alpha(0.5)

plt.show()

顯示效果為:


6.3D圖表

3D圖表也是能我們展示出超想象力的視覺效果的圖表。

6.1三維散點(diǎn)圖

首先來看看三維的散點(diǎn)圖,源碼:

import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

data = np.random.randint(0, 255, size=[40, 40, 40])

x, y, z = data[0], data[1], data[2]

ax = plt.subplot(111, projection='3d')

ax.scatter(x[:10], y[:10], z[:10], c='y')

ax.scatter(x[10:20], y[10:20], z[10:20], c='r')

ax.scatter(x[30:40], y[30:40], z[30:40], c='g')

ax.set_zlabel('Z')

ax.set_ylabel('Y')

ax.set_xlabel('X')

plt.show()

顯示效果為:




怎么樣,效果很酷把,好今天就給大家介紹到這里,如果你有任何問題,可以加到我的一個(gè)交流?:548+377+875 源碼也有!教程也有!一起交流 快速入門!


本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
第七章 使用 matplotlib 繪制堆疊條形圖
pandas可視化(2)【官方文檔解讀】-- 條形圖、直方圖
Python中用matplotlib.pyplot畫圖總結(jié)
Matplotlib繪制的27個(gè)常用圖(附對應(yīng)代碼實(shí)現(xiàn))
Python--Matplotlib(超級詳細(xì)帶大量實(shí)例)
如何駕馭Matplotlib?<Part1>
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服