Skip to content

Functionalizing examples/pie_and_polar_charts #3577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
pep8 and move data to after function
  • Loading branch information
MC-Escherichia committed Sep 27, 2014
commit c035e4f4c70de26539d521972c413b7d24d88e3c
25 changes: 13 additions & 12 deletions examples/pie_and_polar_charts/pie_demo_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,8 @@
"""
import matplotlib.pyplot as plt

# Example data:
# The slices will be ordered and plotted counter-clockwise.
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
sizes = [15, 30, 45, 10]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')
ax = plt.subplot(111)

def pie_demo_features(ax,sizes,labels,colors,explode):
def pie_demo_features(ax, sizes, labels, colors, explode):
"""
produces a simple pie plot on ax according to sizes, labels, colors and explode.

Expand Down Expand Up @@ -54,11 +47,19 @@ def pie_demo_features(ax,sizes,labels,colors,explode):
Returns artist for further modification.
"""

pi = ax.pie(sizes,explode=explode,labels=labels,colors=colors,
pi = ax.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=90)
# Set aspect rtio to be equal so that pie is drawn as a circle.
ax.axis('equal');
return pi;
ax.axis('equal')
return pi

# Example data:
# The slices will be ordered and plotted counter-clockwise.
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
sizes = [15, 30, 45, 10]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')
ax = plt.subplot(111)

pie_demo_features(ax,sizes,labels,colors,explode)
pie_demo_features(ax, sizes, labels, colors, explode)
plt.show()
17 changes: 8 additions & 9 deletions examples/pie_and_polar_charts/polar_bar_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
import matplotlib.pyplot as plt


# Generate Example Data.
N = 20
ex_theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False)
ex_radii = 10 * np.random.rand(N)
ex_width = np.pi / 4 * np.random.rand(N)

def polar_bar_demo(ax,theta,radii,width):
def polar_bar_demo(ax, theta, radii, width):
"""
produces a randomly colored polar plot given three arrays,
theta, radii,width .
Expand Down Expand Up @@ -44,10 +38,15 @@ def polar_bar_demo(ax,theta,radii,width):
bar.set_facecolor(plt.cm.jet(r / 10.))
bar.set_alpha(0.5)


return bars

# Generate Example Data.
N = 20
ex_theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False)
ex_radii = 10 * np.random.rand(N)
ex_width = np.pi / 4 * np.random.rand(N)

ax = plt.subplot(111, polar=True)
polar_bar_demo(ax,ex_theta,ex_radii,ex_width)
polar_bar_demo(ax, ex_theta, ex_radii, ex_width)

plt.show()
18 changes: 10 additions & 8 deletions examples/pie_and_polar_charts/polar_scatter_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@
import numpy as np
import matplotlib.pyplot as plt

# example data
N = 150
ex_r = 2 * np.random.rand(N)
ex_theta = 2 * np.pi * np.random.rand(N)
ex_area = 200 * r**2 * np.random.rand(N)
ex_colors = theta

def polar_scatter_demo(ax,theta,r,area,colors):
def polar_scatter_demo(ax, theta, r, area, colors):
"""
produces a randomly colored polar plot given three arrays,
theta, radii,width .
Expand Down Expand Up @@ -45,8 +39,16 @@ def polar_scatter_demo(ax,theta,r,area,colors):
c.set_alpha(0.75)
return c


# example data
N = 150
ex_r = 2 * np.random.rand(N)
ex_theta = 2 * np.pi * np.random.rand(N)
ex_area = 200 * r ** 2 * np.random.rand(N)
ex_colors = theta

ax = plt.subplot(111, polar=True)
polar_scatter_demo(ax,ex_theta,ex_r,ex_area,ex_colors)

polar_scatter_demo(ax, ex_theta, ex_r, ex_area, ex_colors)

plt.show()