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

實例代碼:
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繪制餅圖散點圖實例代碼的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!
相關(guān)文章
Python中Django框架下的staticfiles使用簡介
這篇文章主要介紹了Python中Django框架下的staticfiles使用簡介,staticfiles是一個幫助Django管理靜態(tài)資源的工具,需要的朋友可以參考下2015-05-05
python中實現(xiàn)迭代器(iterator)的方法示例
我們經(jīng)常需要遍歷一個對象中的元素,在Python中這種功能是通過迭代器來實現(xiàn)的。下面這篇文章主要給大家介紹了python中實現(xiàn)迭代器(iterator)的方法示例,需要的朋友可以參考借鑒,下面來一起看看吧。2017-01-01
如何使用python轉(zhuǎn)移mysql數(shù)據(jù)庫中的全部數(shù)據(jù)
這篇文章主要為大家詳細介紹了如何使用python轉(zhuǎn)移mysql數(shù)據(jù)庫中的全部數(shù)據(jù),文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起了解下2024-11-11
Python?Pandas教程之series 上的轉(zhuǎn)換操作
這篇文章主要介紹了Python?Pandas教程之series上的轉(zhuǎn)換操作,文章通過圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-09-09

