Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd55ab2

Browse files
committed
#2899 almost final changes for adding wedge and text kwargs to pie. needs feedback on generated pyplot
1 parent 3ceade6 commit bd55ab2

4 files changed

Lines changed: 53 additions & 34 deletions

File tree

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2014-03-22 Added the keyword arguments wedgeprops and textprops to pie.
2+
Users can control the wedge and text properties of the pie
3+
in more detail, if they choose.
4+
15
2014-03-17 Bug was fixed in append_axes from the AxesDivider class would not
26
append axes in the right location with respect to the reference
37
locator axes

doc/users/whats_new.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ specifically the Skew-T used in meteorology.
131131

132132
.. plot:: mpl_examples/api/skewt.py
133133

134+
Support for specifying properties of wedge and text in pie charts.
135+
``````````````````````````````````````````````````````````````
136+
Added the `kwargs` 'wedgeprops' and 'textprops' to :func:`~matplotlib.Axes.pie`
137+
to accept properties for wedge and text objects in a pie. For example, one can
138+
specify wedgeprops = {'linewidth':3} to specify the width of the borders of
139+
the wedges in the pie. For more properties that the user can specify, look at
140+
the docs for the wedge and text objects.
141+
134142

135143
Date handling
136144
-------------

lib/matplotlib/axes/_axes.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,7 +2337,7 @@ def stem(self, *args, **kwargs):
23372337
def pie(self, x, explode=None, labels=None, colors=None,
23382338
autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1,
23392339
startangle=None, radius=None, counterclock=True,
2340-
**kwargs):
2340+
wedgeprops=None, textprops=None):
23412341
r"""
23422342
Plot a pie chart.
23432343
@@ -2347,7 +2347,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
23472347
colors=('b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'),
23482348
autopct=None, pctdistance=0.6, shadow=False,
23492349
labeldistance=1.1, startangle=None, radius=None,
2350-
wedgeargs={'linewidth':None}, textargs={},
2350+
counterclock=True, wedgeprops=None, textprops=None,
23512351
)
23522352
23532353
Make a pie chart of array *x*. The fractional area of each
@@ -2396,6 +2396,15 @@ def pie(self, x, explode=None, labels=None, colors=None,
23962396
*counterclock*: [ *False* | *True* ]
23972397
Specify fractions direction, clockwise or counterclockwise.
23982398
2399+
*wedgeprops*: [ *None* | dict of key value pairs ]
2400+
Dict of arguments passed to the wedge objects making the pie.
2401+
For example, you can pass in wedgeprops = { 'linewidth' : 3 }
2402+
to set the width of the wedge border lines equal to 3.
2403+
For more details, look at the doc/arguments of the wedge object.
2404+
2405+
*textprops*: [ *None* | dict of key value pairs ]
2406+
Dict of arguments to pass to the text objects.
2407+
23992408
The pie chart will probably look best if the figure and axes are
24002409
square, or the Axes aspect is equal. e.g.::
24012410
@@ -2448,8 +2457,8 @@ def pie(self, x, explode=None, labels=None, colors=None,
24482457
else:
24492458
theta1 = startangle / 360.0
24502459

2451-
wedgeargs = kwargs.get('wedgeargs', {})
2452-
textargs = kwargs.get('textargs', {})
2460+
wedgeprops = {} if (wedgeprops is None) else wedgeprops
2461+
textprops = {} if (textprops is None) else textprops
24532462

24542463
texts = []
24552464
slices = []
@@ -2466,7 +2475,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
24662475
w = mpatches.Wedge((x, y), radius, 360. * min(theta1, theta2),
24672476
360. * max(theta1, theta2),
24682477
facecolor=colors[i % len(colors)],
2469-
**wedgeargs)
2478+
**wedgeprops)
24702479
slices.append(w)
24712480
self.add_patch(w)
24722481
w.set_label(label)
@@ -2491,7 +2500,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
24912500
size=rcParams['xtick.labelsize'],
24922501
horizontalalignment=label_alignment,
24932502
verticalalignment='center',
2494-
**textargs)
2503+
**textprops)
24952504

24962505
texts.append(t)
24972506

@@ -2506,13 +2515,10 @@ def pie(self, x, explode=None, labels=None, colors=None,
25062515
raise TypeError(
25072516
'autopct must be callable or a format string')
25082517

2509-
# code review request: not sure if we should pass the
2510-
# textargs to this call as well. Probably should, but
2511-
# someone who knows this better should comment.
25122518
t = self.text(xt, yt, s,
25132519
horizontalalignment='center',
25142520
verticalalignment='center',
2515-
**textargs)
2521+
**textprops)
25162522

25172523

25182524
autotexts.append(t)

lib/matplotlib/pyplot.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,7 +2599,7 @@ def broken_barh(xranges, yrange, hold=None, **kwargs):
25992599
# This function was autogenerated by boilerplate.py. Do not edit as
26002600
# changes will be lost
26012601
@_autogen_docstring(Axes.boxplot)
2602-
def boxplot(x, notch=False, sym='b+', vert=True, whis=1.5, positions=None,
2602+
def boxplot(x, notch=False, sym=u'b+', vert=True, whis=1.5, positions=None,
26032603
widths=None, patch_artist=False, bootstrap=None, usermedians=None,
26042604
conf_intervals=None, meanline=False, showmeans=False, showcaps=True,
26052605
showbox=True, showfliers=True, boxprops=None, labels=None,
@@ -2631,8 +2631,8 @@ def boxplot(x, notch=False, sym='b+', vert=True, whis=1.5, positions=None,
26312631
# changes will be lost
26322632
@_autogen_docstring(Axes.cohere)
26332633
def cohere(x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
2634-
window=mlab.window_hanning, noverlap=0, pad_to=None, sides='default',
2635-
scale_by_freq=None, hold=None, **kwargs):
2634+
window=mlab.window_hanning, noverlap=0, pad_to=None,
2635+
sides=u'default', scale_by_freq=None, hold=None, **kwargs):
26362636
ax = gca()
26372637
# allow callers to override the hold state by passing hold=True|False
26382638
washold = ax.ishold()
@@ -2729,7 +2729,7 @@ def csd(x, y, NFFT=None, Fs=None, Fc=None, detrend=None, window=None,
27292729
# This function was autogenerated by boilerplate.py. Do not edit as
27302730
# changes will be lost
27312731
@_autogen_docstring(Axes.errorbar)
2732-
def errorbar(x, y, yerr=None, xerr=None, fmt='-', ecolor=None, elinewidth=None,
2732+
def errorbar(x, y, yerr=None, xerr=None, fmt=u'-', ecolor=None, elinewidth=None,
27332733
capsize=3, barsabove=False, lolims=False, uplims=False,
27342734
xlolims=False, xuplims=False, errorevery=1, capthick=None,
27352735
hold=None, **kwargs):
@@ -2754,9 +2754,9 @@ def errorbar(x, y, yerr=None, xerr=None, fmt='-', ecolor=None, elinewidth=None,
27542754
# This function was autogenerated by boilerplate.py. Do not edit as
27552755
# changes will be lost
27562756
@_autogen_docstring(Axes.eventplot)
2757-
def eventplot(positions, orientation='horizontal', lineoffsets=1, linelengths=1,
2758-
linewidths=None, colors=None, linestyles='solid', hold=None,
2759-
**kwargs):
2757+
def eventplot(positions, orientation=u'horizontal', lineoffsets=1,
2758+
linelengths=1, linewidths=None, colors=None, linestyles=u'solid',
2759+
hold=None, **kwargs):
27602760
ax = gca()
27612761
# allow callers to override the hold state by passing hold=True|False
27622762
washold = ax.ishold()
@@ -2832,9 +2832,9 @@ def fill_betweenx(y, x1, x2=0, where=None, hold=None, **kwargs):
28322832
# This function was autogenerated by boilerplate.py. Do not edit as
28332833
# changes will be lost
28342834
@_autogen_docstring(Axes.hexbin)
2835-
def hexbin(x, y, C=None, gridsize=100, bins=None, xscale='linear',
2836-
yscale='linear', extent=None, cmap=None, norm=None, vmin=None,
2837-
vmax=None, alpha=None, linewidths=None, edgecolors='none',
2835+
def hexbin(x, y, C=None, gridsize=100, bins=None, xscale=u'linear',
2836+
yscale=u'linear', extent=None, cmap=None, norm=None, vmin=None,
2837+
vmax=None, alpha=None, linewidths=None, edgecolors=u'none',
28382838
reduce_C_function=np.mean, mincnt=None, marginals=False, hold=None,
28392839
**kwargs):
28402840
ax = gca()
@@ -2860,7 +2860,7 @@ def hexbin(x, y, C=None, gridsize=100, bins=None, xscale='linear',
28602860
# changes will be lost
28612861
@_autogen_docstring(Axes.hist)
28622862
def hist(x, bins=10, range=None, normed=False, weights=None, cumulative=False,
2863-
bottom=None, histtype='bar', align='mid', orientation='vertical',
2863+
bottom=None, histtype=u'bar', align=u'mid', orientation=u'vertical',
28642864
rwidth=None, log=False, color=None, label=None, stacked=False,
28652865
hold=None, **kwargs):
28662866
ax = gca()
@@ -2904,8 +2904,8 @@ def hist2d(x, y, bins=10, range=None, normed=False, weights=None, cmin=None,
29042904
# This function was autogenerated by boilerplate.py. Do not edit as
29052905
# changes will be lost
29062906
@_autogen_docstring(Axes.hlines)
2907-
def hlines(y, xmin, xmax, colors='k', linestyles='solid', label='', hold=None,
2908-
**kwargs):
2907+
def hlines(y, xmin, xmax, colors=u'k', linestyles=u'solid', label=u'',
2908+
hold=None, **kwargs):
29092909
ax = gca()
29102910
# allow callers to override the hold state by passing hold=True|False
29112911
washold = ax.ishold()
@@ -3046,7 +3046,7 @@ def phase_spectrum(x, Fs=None, Fc=None, window=None, pad_to=None, sides=None,
30463046
@_autogen_docstring(Axes.pie)
30473047
def pie(x, explode=None, labels=None, colors=None, autopct=None,
30483048
pctdistance=0.6, shadow=False, labeldistance=1.1, startangle=None,
3049-
radius=None, hold=None):
3049+
radius=None, counterclock=True, linewidth=None, hold=None):
30503050
ax = gca()
30513051
# allow callers to override the hold state by passing hold=True|False
30523052
washold = ax.ishold()
@@ -3057,7 +3057,8 @@ def pie(x, explode=None, labels=None, colors=None, autopct=None,
30573057
ret = ax.pie(x, explode=explode, labels=labels, colors=colors,
30583058
autopct=autopct, pctdistance=pctdistance, shadow=shadow,
30593059
labeldistance=labeldistance, startangle=startangle,
3060-
radius=radius)
3060+
radius=radius, counterclock=counterclock,
3061+
linewidth=linewidth)
30613062
draw_if_interactive()
30623063
finally:
30633064
ax.hold(washold)
@@ -3085,7 +3086,7 @@ def plot(*args, **kwargs):
30853086
# This function was autogenerated by boilerplate.py. Do not edit as
30863087
# changes will be lost
30873088
@_autogen_docstring(Axes.plot_date)
3088-
def plot_date(x, y, fmt='o', tz=None, xdate=True, ydate=False, hold=None,
3089+
def plot_date(x, y, fmt=u'o', tz=None, xdate=True, ydate=False, hold=None,
30893090
**kwargs):
30903091
ax = gca()
30913092
# allow callers to override the hold state by passing hold=True|False
@@ -3164,7 +3165,7 @@ def quiverkey(*args, **kw):
31643165
# This function was autogenerated by boilerplate.py. Do not edit as
31653166
# changes will be lost
31663167
@_autogen_docstring(Axes.scatter)
3167-
def scatter(x, y, s=20, c='b', marker='o', cmap=None, norm=None, vmin=None,
3168+
def scatter(x, y, s=20, c=u'b', marker=u'o', cmap=None, norm=None, vmin=None,
31683169
vmax=None, alpha=None, linewidths=None, verts=None, hold=None,
31693170
**kwargs):
31703171
ax = gca()
@@ -3302,7 +3303,7 @@ def step(x, y, *args, **kwargs):
33023303
# changes will be lost
33033304
@_autogen_docstring(Axes.streamplot)
33043305
def streamplot(x, y, u, v, density=1, linewidth=None, color=None, cmap=None,
3305-
norm=None, arrowsize=1, arrowstyle='-|>', minlength=0.1,
3306+
norm=None, arrowsize=1, arrowstyle=u'-|>', minlength=0.1,
33063307
transform=None, zorder=1, hold=None):
33073308
ax = gca()
33083309
# allow callers to override the hold state by passing hold=True|False
@@ -3397,8 +3398,8 @@ def triplot(*args, **kwargs):
33973398
# This function was autogenerated by boilerplate.py. Do not edit as
33983399
# changes will be lost
33993400
@_autogen_docstring(Axes.vlines)
3400-
def vlines(x, ymin, ymax, colors='k', linestyles='solid', label='', hold=None,
3401-
**kwargs):
3401+
def vlines(x, ymin, ymax, colors=u'k', linestyles=u'solid', label=u'',
3402+
hold=None, **kwargs):
34023403
ax = gca()
34033404
# allow callers to override the hold state by passing hold=True|False
34043405
washold = ax.ishold()
@@ -3463,7 +3464,7 @@ def cla():
34633464
# This function was autogenerated by boilerplate.py. Do not edit as
34643465
# changes will be lost
34653466
@docstring.copy_dedent(Axes.grid)
3466-
def grid(b=None, which='major', axis='both', **kwargs):
3467+
def grid(b=None, which=u'major', axis=u'both', **kwargs):
34673468
ret = gca().grid(b=b, which=which, axis=axis, **kwargs)
34683469
draw_if_interactive()
34693470
return ret
@@ -3511,15 +3512,15 @@ def ticklabel_format(**kwargs):
35113512
# This function was autogenerated by boilerplate.py. Do not edit as
35123513
# changes will be lost
35133514
@docstring.copy_dedent(Axes.locator_params)
3514-
def locator_params(axis='both', tight=None, **kwargs):
3515+
def locator_params(axis=u'both', tight=None, **kwargs):
35153516
ret = gca().locator_params(axis=axis, tight=tight, **kwargs)
35163517
draw_if_interactive()
35173518
return ret
35183519

35193520
# This function was autogenerated by boilerplate.py. Do not edit as
35203521
# changes will be lost
35213522
@docstring.copy_dedent(Axes.tick_params)
3522-
def tick_params(axis='both', **kwargs):
3523+
def tick_params(axis=u'both', **kwargs):
35233524
ret = gca().tick_params(axis=axis, **kwargs)
35243525
draw_if_interactive()
35253526
return ret
@@ -3535,7 +3536,7 @@ def margins(*args, **kw):
35353536
# This function was autogenerated by boilerplate.py. Do not edit as
35363537
# changes will be lost
35373538
@docstring.copy_dedent(Axes.autoscale)
3538-
def autoscale(enable=True, axis='both', tight=None):
3539+
def autoscale(enable=True, axis=u'both', tight=None):
35393540
ret = gca().autoscale(enable=enable, axis=axis, tight=tight)
35403541
draw_if_interactive()
35413542
return ret

0 commit comments

Comments
 (0)