Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a623ff3

Browse filesBrowse files
committed
more subplots, cleanup of old import * style
1 parent d42109a commit a623ff3
Copy full SHA for a623ff3
Expand file treeCollapse file tree

37 files changed

+85
-102
lines changed

‎examples/animation/old_animation/animation_blit_qt.py

Copy file name to clipboardExpand all lines: examples/animation/old_animation/animation_blit_qt.py
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from __future__ import print_function
55

6-
import os, sys
6+
import sys
77
import matplotlib
88
matplotlib.use('QtAgg') # qt3 example
99

@@ -16,21 +16,21 @@
1616
FALSE = 0
1717
ITERS = 1000
1818

19-
import pylab as p
19+
import matplotlib.pyplot as plt
2020
import numpy as npy
2121
import time
2222

2323
class BlitQT(QObject):
2424
def __init__(self):
2525
QObject.__init__(self, None, "app")
2626

27-
fig, self.ax = plt.subplots()
27+
self.ax = plt.axes()
2828
self.canvas = self.ax.figure.canvas
2929
self.cnt = 0
3030

3131
# create the initial line
3232
self.x = npy.arange(0,2*npy.pi,0.01)
33-
self.line, = p.plot(self.x, npy.sin(self.x), animated=True, lw=2)
33+
self.line, = plt.plot(self.x, npy.sin(self.x), animated=True, lw=2)
3434

3535
self.background = None
3636

@@ -55,12 +55,12 @@ def timerEvent(self, evt):
5555
else:
5656
self.cnt += 1
5757

58-
p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
59-
p.grid() # to ensure proper background restore
58+
plt.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
59+
plt.grid() # to ensure proper background restore
6060

6161
app = BlitQT()
6262
# for profiling
6363
app.tstart = time.time()
6464
app.startTimer(0)
6565

66-
p.show()
66+
plt.show()

‎examples/animation/old_animation/animation_blit_tk.py

Copy file name to clipboardExpand all lines: examples/animation/old_animation/animation_blit_tk.py
+1-1Lines 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

Copy file name to clipboardExpand all lines: examples/animation/old_animation/animation_blit_wx.py
+1Lines 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

Copy file name to clipboardExpand all lines: examples/animation/old_animation/histogram_tkagg.py
-1Lines 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

Copy file name to clipboardExpand all lines: examples/animation/old_animation/simple_idle_wx.py
-1Lines 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

Copy file name to clipboardExpand all lines: examples/animation/old_animation/simple_timer_wx.py
-1Lines 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

Copy file name to clipboardExpand all lines: examples/animation/old_animation/strip_chart_demo.py
+2-3Lines 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

Copy file name to clipboardExpand all lines: examples/animation/strip_chart_demo.py
-1Lines 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

Copy file name to clipboardExpand all lines: examples/api/joinstyle.py
-1Lines 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/path_patch_demo.py

Copy file name to clipboardExpand all lines: examples/api/path_patch_demo.py
-1Lines 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/quad_bezier.py

Copy file name to clipboardExpand all lines: examples/api/quad_bezier.py
-1Lines 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

Copy file name to clipboardExpand all lines: examples/api/watermark_image.py
-1Lines 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

Copy file name to clipboardExpand all lines: examples/event_handling/path_editor.py
+1-1Lines 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

Copy file name to clipboardExpand all lines: examples/pylab_examples/agg_buffer_to_array.py
+3-4Lines 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

Copy file name to clipboardExpand all lines: examples/pylab_examples/barchart_demo2.py
-1Lines 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

Copy file name to clipboardExpand all lines: examples/pylab_examples/boxplot_demo3.py
-1Lines 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

Copy file name to clipboardExpand all lines: examples/pylab_examples/centered_ticklabels.py
-2Lines 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

Copy file name to clipboardExpand all lines: examples/pylab_examples/coords_report.py
+1-1Lines 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

Copy file name to clipboardExpand all lines: examples/pylab_examples/cursor_demo.py
+1-1Lines 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

Copy file name to clipboardExpand all lines: examples/pylab_examples/custom_ticker1.py
+6-5Lines 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

Copy file name to clipboardExpand all lines: examples/pylab_examples/dashpointlabel.py
+2-2Lines 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

Copy file name to clipboardExpand all lines: examples/pylab_examples/date_demo1.py
+2-2Lines 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

Copy file name to clipboardExpand all lines: examples/pylab_examples/date_demo2.py
+2-2Lines 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

Copy file name to clipboardExpand all lines: examples/pylab_examples/date_demo_convert.py
+2-2Lines 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

Copy file name to clipboardExpand all lines: examples/pylab_examples/date_demo_rrule.py
+6-5Lines 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

Copy file name to clipboardExpand all lines: examples/pylab_examples/date_index_formatter.py
+2-2Lines 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

Copy file name to clipboardExpand all lines: examples/pylab_examples/fill_between_demo.py
+4-12Lines 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()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.