Movatterモバイル変換


[0]ホーム

URL:


You are reading an old version of the documentation (v2.0.0). For the latest version seehttps://matplotlib.org/stable/
matplotlib

Navigation


Travis-CI:

Related Topics

This Page

Quick search

api example code: scatter_piecharts.py

(Source code,png,pdf)

../../_images/scatter_piecharts.png
"""===================================Scatter plot with pie chart markers===================================This example makes custom 'pie charts' as the markers for a scatter plot.Thanks to Manuel Metz for the example"""importmathimportnumpyasnpimportmatplotlib.pyplotasplt# first define the ratiosr1=0.2# 20%r2=r1+0.4# 40%# define some sizes of the scatter markersizes=[60,80,120]# calculate the points of the first pie marker## these are just the origin (0,0) +# some points on a circle cos,sinx=[0]+np.cos(np.linspace(0,2*math.pi*r1,10)).tolist()y=[0]+np.sin(np.linspace(0,2*math.pi*r1,10)).tolist()xy1=list(zip(x,y))s1=max(max(x),max(y))# ...x=[0]+np.cos(np.linspace(2*math.pi*r1,2*math.pi*r2,10)).tolist()y=[0]+np.sin(np.linspace(2*math.pi*r1,2*math.pi*r2,10)).tolist()xy2=list(zip(x,y))s2=max(max(x),max(y))x=[0]+np.cos(np.linspace(2*math.pi*r2,2*math.pi,10)).tolist()y=[0]+np.sin(np.linspace(2*math.pi*r2,2*math.pi,10)).tolist()xy3=list(zip(x,y))s3=max(max(x),max(y))fig,ax=plt.subplots()ax.scatter(np.arange(3),np.arange(3),marker=(xy1,0),s=[s1*s1*_for_insizes],facecolor='blue')ax.scatter(np.arange(3),np.arange(3),marker=(xy2,0),s=[s2*s2*_for_insizes],facecolor='green')ax.scatter(np.arange(3),np.arange(3),marker=(xy3,0),s=[s3*s3*_for_insizes],facecolor='red')plt.show()

Keywords: python, matplotlib, pylab, example, codex (seeSearch examples)

© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012 - 2016 The Matplotlib development team. Last updated on Feb 20, 2017. Created usingSphinx 1.5.2.

[8]ページ先頭

©2009-2025 Movatter.jp