python+matplotlib繪制餅圖散點(diǎn)圖實(shí)例代碼
本文是從matplotlib官網(wǎng)上摘錄下來(lái)的一個(gè)實(shí)例,實(shí)現(xiàn)的功能是Python+matplotlib繪制自定義餅圖作為散點(diǎn)圖的標(biāo)記,具體如下。
首先看下演示效果

實(shí)例代碼:
import numpy as np
import matplotlib.pyplot as plt
# first define the ratios
r1 = 0.2 # 20%
r2 = r1 + 0.4 # 40%
# define some sizes of the scatter marker
sizes = np.array([60, 80, 120])
# calculate the points of the first pie marker
#
# these are just the origin (0,0) +
# some points on a circle cos,sin
x = [0] + np.cos(np.linspace(0, 2 * np.pi * r1, 10)).tolist()
y = [0] + np.sin(np.linspace(0, 2 * np.pi * r1, 10)).tolist()
xy1 = list(zip(x, y))
s1 = np.max(xy1)
x = [0] + np.cos(np.linspace(2 * np.pi * r1, 2 * np.pi * r2, 10)).tolist()
y = [0] + np.sin(np.linspace(2 * np.pi * r1, 2 * np.pi * r2, 10)).tolist()
xy2 = list(zip(x, y))
s2 = np.max(xy2)
x = [0] + np.cos(np.linspace(2 * np.pi * r2, 2 * np.pi, 10)).tolist()
y = [0] + np.sin(np.linspace(2 * np.pi * r2, 2 * np.pi, 10)).tolist()
xy3 = list(zip(x, y))
s3 = np.max(xy3)
fig, ax = plt.subplots()
ax.scatter(range(3), range(3), marker=(xy1, 0),
s=s1 ** 2 * sizes, facecolor='blue')
ax.scatter(range(3), range(3), marker=(xy2, 0),
s=s2 ** 2 * sizes, facecolor='green')
ax.scatter(range(3), range(3), marker=(xy3, 0),
s=s3 ** 2 * sizes, facecolor='red')
plt.show()
總結(jié)
以上就是本文關(guān)于python+matplotlib繪制餅圖散點(diǎn)圖實(shí)例代碼的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!
相關(guān)文章
PyTorch基礎(chǔ)之torch.nn.CrossEntropyLoss交叉熵?fù)p失
這篇文章主要介紹了PyTorch基礎(chǔ)之torch.nn.CrossEntropyLoss交叉熵?fù)p失講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02
Python selenium抓取微博內(nèi)容的示例代碼
本篇文章主要介紹了Python selenium抓取微博內(nèi)容的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-05-05
簡(jiǎn)單了解python關(guān)鍵字global nonlocal區(qū)別
這篇文章主要介紹了簡(jiǎn)單了解python關(guān)鍵字global nonlocal區(qū)別,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-09-09

