Skip to content

Commit 376a0b4

Browse files
ivanovmdboom
authored andcommitted
more subplots, cleanup of old import * style
1 parent 8d1ee03 commit 376a0b4

32 files changed

+59
-76
lines changed

examples/animation/old_animation/animation_blit_tk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import time
1313

1414
fig, ax = plt.subplots()
15-
canvas = ax.figure.canvas
15+
canvas = fig.canvas
1616

1717

1818
# create the initial line

examples/animation/old_animation/animation_blit_wx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import matplotlib
1111
matplotlib.use('WXAgg')
1212
matplotlib.rcParams['toolbar'] = 'None'
13+
import matplotlib.pyplot as plt
1314

1415
import wx
1516
import sys

examples/animation/old_animation/histogram_tkagg.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
This example shows how to use a path patch to draw a bunch of
33
rectangles for an animated histogram
44
"""
5-
import time
65
import numpy as np
76
import matplotlib
87
matplotlib.use('TkAgg') # do this before importing pylab

examples/animation/old_animation/simple_idle_wx.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
A simple example of an animated plot using a wx backend
33
"""
44
from __future__ import print_function
5-
import time
65
import numpy as np
76
import matplotlib
87
matplotlib.use('WXAgg') # do this before importing pylab

examples/animation/old_animation/simple_timer_wx.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""
33
A simple example of an animated plot using a wx backend
44
"""
5-
import time
65
import numpy as np
76
import matplotlib
87
matplotlib.use('WXAgg') # do this before importing pylab

examples/animation/old_animation/strip_chart_demo.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import matplotlib
1414
matplotlib.use('GTKAgg')
1515
import numpy as np
16+
import matplotlib.pyplot as plt
1617
from matplotlib.lines import Line2D
1718

1819

@@ -62,10 +63,8 @@ def update(self, *args):
6263
return True
6364

6465

65-
from pylab import figure, show
66-
6766
fig, ax = plt.subplots()
6867
scope = Scope(ax)
6968
gobject.idle_add(scope.update)
7069

71-
show()
70+
plt.show()

examples/animation/strip_chart_demo.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Emulate an oscilloscope. Requires the animation API introduced in
33
matplotlib 1.0 SVN.
44
"""
5-
import matplotlib
65
import numpy as np
76
from matplotlib.lines import Line2D
87
import matplotlib.pyplot as plt

examples/api/joinstyle.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55

66
import numpy as np
7-
import matplotlib
87
import matplotlib.pyplot as plt
98

109
def plot_angle(ax, x, y, angle, style):

examples/api/quad_bezier.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import numpy as np
21
import matplotlib.path as mpath
32
import matplotlib.patches as mpatches
43
import matplotlib.pyplot as plt

examples/api/watermark_image.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44
from __future__ import print_function
55
import numpy as np
6-
import matplotlib
76
import matplotlib.cbook as cbook
87
import matplotlib.image as image
98
import matplotlib.pyplot as plt

examples/event_handling/path_editor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def pathpatch_changed(self, pathpatch):
7171
'this method is called whenever the pathpatchgon object is called'
7272
# only copy the artist props to the line (except visibility)
7373
vis = self.line.get_visible()
74-
Artist.update_from(self.line, pathpatch)
74+
plt.Artist.update_from(self.line, pathpatch)
7575
self.line.set_visible(vis) # don't use the pathpatch visibility state
7676

7777

examples/pylab_examples/agg_buffer_to_array.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import matplotlib
2-
from pylab import figure, show
1+
import matplotlib.pyplot as plt
32
import numpy as np
43

54
# make an agg figure
@@ -17,7 +16,7 @@
1716
X.shape = h,w,4
1817

1918
# now display the array X as an Axes in a new figure
20-
fig2 = figure()
19+
fig2 = plt.figure()
2120
ax2 = fig2.add_subplot(111, frameon=False)
2221
ax2.imshow(X)
23-
show()
22+
plt.show()

examples/pylab_examples/barchart_demo2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import numpy as np
1212
import matplotlib.pyplot as plt
1313
import pylab
14-
from matplotlib.patches import Polygon
1514
from matplotlib.ticker import MaxNLocator
1615

1716

examples/pylab_examples/boxplot_demo3.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import matplotlib.pyplot as plt
2-
import matplotlib.transforms as mtransforms
32
import numpy as np
43

54
def fakeBootStrapper(n):

examples/pylab_examples/centered_ticklabels.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
# between the major ticks. Here is an example that labels the months,
1313
# centered between the ticks
1414

15-
import datetime
1615
import numpy as np
17-
import matplotlib
1816
import matplotlib.cbook as cbook
1917
import matplotlib.dates as dates
2018
import matplotlib.ticker as ticker

examples/pylab_examples/coords_report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def millions(x):
1010
x = rand(20)
1111
y = 1e7*rand(20)
1212

13-
fig, ax = plt.subplots()
13+
fig, ax = subplots()
1414
ax.fmt_ydata = millions
1515
plot(x, y, 'o')
1616

examples/pylab_examples/cursor_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def mouse_move(self, event):
6868

6969
t = arange(0.0, 1.0, 0.01)
7070
s = sin(2*2*pi*t)
71-
fig, ax = plt.subplots()
71+
fig, ax = subplots()
7272

7373
cursor = Cursor(ax)
7474
#cursor = SnaptoCursor(ax, t, s)

examples/pylab_examples/custom_ticker1.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
millions of dollars on the y axis
1212
"""
1313
from matplotlib.ticker import FuncFormatter
14-
from pylab import *
14+
import matplotlib.pyplot as plt
15+
import numpy as np
1516

16-
x = arange(4)
17+
x = np.arange(4)
1718
money = [1.5e5, 2.5e6, 5.5e6, 2.0e7]
1819

1920
def millions(x, pos):
@@ -24,6 +25,6 @@ def millions(x, pos):
2425

2526
fig, ax = plt.subplots()
2627
ax.yaxis.set_major_formatter(formatter)
27-
bar(x, money)
28-
xticks( x + 0.5, ('Bill', 'Fred', 'Mary', 'Sue') )
29-
show()
28+
plt.bar(x, money)
29+
plt.xticks( x + 0.5, ('Bill', 'Fred', 'Mary', 'Sue') )
30+
plt.show()

examples/pylab_examples/dashpointlabel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pylab
1+
import matplotlib.pyplot as plt
22

33
DATA = ((1, 3),
44
(2, 4),
@@ -34,5 +34,5 @@
3434
ax.set_xlim((0.0, 5.0))
3535
ax.set_ylim((0.0, 5.0))
3636

37-
pylab.show()
37+
plt.show()
3838

examples/pylab_examples/date_demo1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
yahoo finance to get the data for plotting
1515
"""
1616

17-
from pylab import figure, show
17+
import matplotlib.pyplot as plt
1818
from matplotlib.finance import quotes_historical_yahoo
1919
from matplotlib.dates import YearLocator, MonthLocator, DateFormatter
2020
import datetime
@@ -49,4 +49,4 @@ def price(x): return '$%1.2f'%x
4949
ax.grid(True)
5050

5151
fig.autofmt_xdate()
52-
show()
52+
plt.show()

examples/pylab_examples/date_demo2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88
from __future__ import print_function
99
import datetime
10-
from pylab import figure, show
10+
import matplotlib.pyplot as plt
1111
from matplotlib.dates import MONDAY
1212
from matplotlib.finance import quotes_historical_yahoo
1313
from matplotlib.dates import MonthLocator, WeekdayLocator, DateFormatter
@@ -44,4 +44,4 @@
4444

4545
fig.autofmt_xdate()
4646

47-
show()
47+
plt.show()

examples/pylab_examples/date_demo_convert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

33
import datetime
4-
from matplotlib.pyplot import figure, show
4+
import matplotlib.pyplot as plt
55
from matplotlib.dates import DayLocator, HourLocator, DateFormatter, drange
66
from numpy import arange
77

@@ -30,4 +30,4 @@
3030
ax.fmt_xdata = DateFormatter('%Y-%m-%d %H:%M:%S')
3131
fig.autofmt_xdate()
3232

33-
show()
33+
plt.show()

examples/pylab_examples/date_demo_rrule.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
66
See https://moin.conectiva.com.br/DateUtil for help with rrules
77
"""
8-
from pylab import *
8+
import matplotlib.pyplot as plt
99
from matplotlib.dates import YEARLY, DateFormatter, rrulewrapper, RRuleLocator, drange
10+
import numpy as np
1011
import datetime
1112

1213
# tick every 5th easter
@@ -18,14 +19,14 @@
1819
delta = datetime.timedelta(days=100)
1920

2021
dates = drange(date1, date2, delta)
21-
s = rand(len(dates)) # make up some random y values
22+
s = np.random.rand(len(dates)) # make up some random y values
2223

2324

2425
fig, ax = plt.subplots()
25-
plot_date(dates, s)
26+
plt.plot_date(dates, s)
2627
ax.xaxis.set_major_locator(loc)
2728
ax.xaxis.set_major_formatter(formatter)
2829
labels = ax.get_xticklabels()
29-
setp(labels, rotation=30, fontsize=10)
30+
plt.setp(labels, rotation=30, fontsize=10)
3031

31-
show()
32+
plt.show()

examples/pylab_examples/date_index_formatter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from __future__ import print_function
1212
import numpy
1313
from matplotlib.mlab import csv2rec
14-
from pylab import figure, show
14+
import matplotlib.pyplot as plt
1515
import matplotlib.cbook as cbook
1616
from matplotlib.ticker import Formatter
1717

@@ -37,4 +37,4 @@ def __call__(self, x, pos=0):
3737
ax.xaxis.set_major_formatter(formatter)
3838
ax.plot(numpy.arange(len(r)), r.close, 'o-')
3939
fig.autofmt_xdate()
40-
show()
40+
plt.show()

examples/pylab_examples/fill_between_demo.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
#!/usr/bin/env python
2-
import matplotlib.mlab as mlab
3-
from matplotlib.pyplot import figure, show
2+
import matplotlib.pyplot as plt
43
import numpy as np
54

65
x = np.arange(0.0, 2, 0.01)
76
y1 = np.sin(2*np.pi*x)
87
y2 = 1.2*np.sin(4*np.pi*x)
98

10-
fig = figure()
11-
ax1 = fig.add_subplot(311)
12-
ax2 = fig.add_subplot(312, sharex=ax1)
13-
ax3 = fig.add_subplot(313, sharex=ax1)
9+
fig, (ax1, ax2, ax3) = plt.subplots(3,1, sharex=True)
1410

1511
ax1.fill_between(x, 0, y1)
1612
ax1.set_ylabel('between y1 and 0')
@@ -26,16 +22,14 @@
2622
# this is different than calling
2723
# fill_between(x[where], y1[where],y2[where]
2824
# because of edge effects over multiple contiguous regions.
29-
fig = figure()
30-
ax = fig.add_subplot(211)
25+
fig, (ax, ax1) = plt.subplots(2, 1, sharex=True)
3126
ax.plot(x, y1, x, y2, color='black')
3227
ax.fill_between(x, y1, y2, where=y2>=y1, facecolor='green', interpolate=True)
3328
ax.fill_between(x, y1, y2, where=y2<=y1, facecolor='red', interpolate=True)
3429
ax.set_title('fill between where')
3530

3631
# Test support for masked arrays.
3732
y2 = np.ma.masked_greater(y2, 1.0)
38-
ax1 = fig.add_subplot(212, sharex=ax)
3933
ax1.plot(x, y1, x, y2, color='black')
4034
ax1.fill_between(x, y1, y2, where=y2>=y1, facecolor='green', interpolate=True)
4135
ax1.fill_between(x, y1, y2, where=y2<=y1, facecolor='red', interpolate=True)
@@ -61,6 +55,4 @@
6155
ax.fill_between(x, 0, 1, where=y<-theta, facecolor='red', alpha=0.5, transform=trans)
6256

6357

64-
65-
show()
66-
58+
plt.show()

examples/pylab_examples/finance_demo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
from pylab import *
2+
import matplotlib.pyplot as plt
33
from matplotlib.dates import DateFormatter, WeekdayLocator, HourLocator, \
44
DayLocator, MONDAY
55
from matplotlib.finance import quotes_historical_yahoo, candlestick,\
@@ -19,7 +19,7 @@
1919
if len(quotes) == 0:
2020
raise SystemExit
2121

22-
fig, ax = subplots()
22+
fig, ax = plt.subplots()
2323
fig.subplots_adjust(bottom=0.2)
2424
ax.xaxis.set_major_locator(mondays)
2525
ax.xaxis.set_minor_locator(alldays)
@@ -31,7 +31,7 @@
3131

3232
ax.xaxis_date()
3333
ax.autoscale_view()
34-
setp( gca().get_xticklabels(), rotation=45, horizontalalignment='right')
34+
plt.setp( plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')
3535

36-
show()
36+
plt.show()
3737

examples/pylab_examples/hist_colormapped.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import numpy as n
2-
from pylab import figure, show
1+
import numpy as np
2+
import matplotlib.pyplot as plt
33
import matplotlib.cm as cm
44
import matplotlib.colors as colors
55

66
fig, ax = plt.subplots()
77
Ntotal = 1000
8-
N, bins, patches = ax.hist(n.random.rand(Ntotal), 20)
8+
N, bins, patches = ax.hist(np.random.rand(Ntotal), 20)
99

1010
#I'll color code by height, but you could use any scalar
1111

@@ -20,4 +20,4 @@
2020
thispatch.set_facecolor(color)
2121

2222

23-
show()
23+
plt.show()

0 commit comments

Comments
 (0)