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

Skip to content

Use sublots in examples #1598

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
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

2012-11-09 Make plt.subplot() without arguments act as subplot(111) - PI

2012-11-08 Replaced plt.figure and plt.subplot calls by the newer, more
convenient single call to plt.subplots() in the documentation
examples - PI

2012-10-05 Add support for saving animations as animated GIFs. - JVDP

2012-08-11 Fix path-closing bug in patches.Polygon, so that regardless
Expand Down
8 changes: 8 additions & 0 deletions doc/users/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ Andrew Dawson added a new keyword argument *extendrect* to
:meth:`~matplotlib.pyplot.colorbar` to optionally make colorbar
extensions rectangular instead of triangular.

Examples now use subplots()
---------------------------
For the sake of brevity and clarity, most of the :ref:`examples
<examples-index>` now use the newer :func:`~matplotlib.pyplot.subplots`, which
creates a figure and one (or multiple) axes object(s) in one call. The old way
involved a call to :func:`~matplotlib.pyplot.figure`, followed by one (or
multiple) :func:`~matplotlib.pyplot.subplot` calls.

Calling subplot() without arguments
-----------------------------------
A call to :func:`~matplotlib.pyplot.subplot` without any arguments now
Expand Down
3 changes: 1 addition & 2 deletions examples/animation/animate_decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def data_gen():
yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)
data_gen.t = 0

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
line, = ax.plot([], [], lw=2)
ax.set_ylim(-1.1, 1.1)
ax.set_xlim(0, 5)
Expand Down
3 changes: 1 addition & 2 deletions examples/animation/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import matplotlib.path as path
import matplotlib.animation as animation

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()

# histogram our data with numpy
data = np.random.randn(1000)
Expand Down
3 changes: 1 addition & 2 deletions examples/animation/old_animation/animate_decay_tk_blit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ def data_gen():
return np.sin(2*np.pi*t) * np.exp(-t/10.)
data_gen.t = 0

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
line, = ax.plot([], [], animated=True, lw=2)
ax.set_ylim(-1.1, 1.1)
ax.set_xlim(0, 5)
Expand Down
12 changes: 6 additions & 6 deletions examples/animation/old_animation/animation_blit_fltk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import fltk
import matplotlib
matplotlib.use('FltkAgg')
import pylab as p
import matplotlib.pyplot as plt
import numpy as npy
import time

Expand Down Expand Up @@ -42,13 +42,13 @@ def update(self,ptr):
sys.exit()
return True

ax = p.subplot(111)
p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
p.grid() # to ensure proper background restore
fig, ax = plt.subplots()
plt.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
plt.grid() # to ensure proper background restore
# create the initial line
x = npy.arange(0,2*npy.pi,0.01)
line, = p.plot(x, npy.sin(x), animated=True)
p.draw()
line, = plt.plot(x, npy.sin(x), animated=True)
plt.draw()
anim=animator(ax)

fltk.Fl.add_idle(anim.update)
Expand Down
3 changes: 1 addition & 2 deletions examples/animation/old_animation/animation_blit_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import matplotlib.pyplot as plt


fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
canvas = fig.canvas

fig.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
Expand Down
3 changes: 1 addition & 2 deletions examples/animation/old_animation/animation_blit_gtk2.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@ def update_line(self, *args):


plt.rcParams["text.usetex"] = False
fig = plt.figure()

ax = fig.add_subplot(111)
fig, ax = plt.subplots()
ax.xaxis.set_animated(True)
ax.yaxis.set_animated(True)
canvas = fig.canvas
Expand Down
14 changes: 7 additions & 7 deletions examples/animation/old_animation/animation_blit_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from __future__ import print_function

import os, sys
import sys
import matplotlib
matplotlib.use('QtAgg') # qt3 example

Expand All @@ -16,21 +16,21 @@
FALSE = 0
ITERS = 1000

import pylab as p
import matplotlib.pyplot as plt
import numpy as npy
import time

class BlitQT(QObject):
def __init__(self):
QObject.__init__(self, None, "app")

self.ax = p.subplot(111)
self.ax = plt.subplot()
self.canvas = self.ax.figure.canvas
self.cnt = 0

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

self.background = None

Expand All @@ -55,12 +55,12 @@ def timerEvent(self, evt):
else:
self.cnt += 1

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

app = BlitQT()
# for profiling
app.tstart = time.time()
app.startTimer(0)

p.show()
plt.show()
16 changes: 8 additions & 8 deletions examples/animation/old_animation/animation_blit_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
matplotlib.use('TkAgg')

import sys
import pylab as p
import matplotlib.pyplot as plt
import numpy as npy
import time

ax = p.subplot(111)
canvas = ax.figure.canvas
fig, ax = plt.subplots()
canvas = fig.canvas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good.



# create the initial line
x = npy.arange(0,2*npy.pi,0.01)
line, = p.plot(x, npy.sin(x), animated=True, lw=2)
line, = plt.plot(x, npy.sin(x), animated=True, lw=2)

def run(*args):
background = canvas.copy_from_bbox(ax.bbox)
Expand All @@ -43,12 +43,12 @@ def run(*args):
run.cnt = 0


p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
p.grid() # to ensure proper background restore
manager = p.get_current_fig_manager()
plt.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
plt.grid() # to ensure proper background restore
manager = plt.get_current_fig_manager()
manager.window.after(100, run)

p.show()
plt.show()



5 changes: 3 additions & 2 deletions examples/animation/old_animation/animation_blit_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import matplotlib
matplotlib.use('WXAgg')
matplotlib.rcParams['toolbar'] = 'None'
import matplotlib.pyplot as plt

import wx
import sys
Expand All @@ -24,8 +25,8 @@
matplotlib.backends.backend_wxagg._use_accelerator(False)


ax = p.subplot(111)
canvas = ax.figure.canvas
fig, ax = plt.subplots()
canvas = fig.canvas


p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
Expand Down
5 changes: 2 additions & 3 deletions examples/animation/old_animation/draggable_legend.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import matplotlib.pyplot as plt


ax = plt.subplot(111)
fig, ax = plt.subplots()
ax.plot([1,2,3], label="test")

l = ax.legend()
d1 = l.draggable()

xy = 1, 2
xy = 1, 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

txt = ax.annotate("Test", xy, xytext=(-30, 30),
textcoords="offset points",
bbox=dict(boxstyle="round",fc=(0.2, 1, 1)),
Expand Down
3 changes: 1 addition & 2 deletions examples/animation/old_animation/gtk_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
line, = ax.plot(np.random.rand(10))
ax.set_ylim(0, 1)

Expand Down
4 changes: 1 addition & 3 deletions examples/animation/old_animation/histogram_tkagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
This example shows how to use a path patch to draw a bunch of
rectangles for an animated histogram
"""
import time
import numpy as np
import matplotlib
matplotlib.use('TkAgg') # do this before importing pylab
Expand All @@ -11,8 +10,7 @@
import matplotlib.patches as patches
import matplotlib.path as path

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()

# histogram our data with numpy
data = np.random.randn(1000)
Expand Down
4 changes: 1 addition & 3 deletions examples/animation/old_animation/simple_anim_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

import matplotlib.pyplot as plt

fig = plt.figure()

ax = fig.add_subplot(111)
fig, ax = plt.subplots()

def animate():
tstart = time.time() # for profiling
Expand Down
3 changes: 1 addition & 2 deletions examples/animation/old_animation/simple_anim_tkagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
matplotlib.use('TkAgg') # do this before importing pylab

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()

def animate():
tstart = time.time() # for profiling
Expand Down
5 changes: 1 addition & 4 deletions examples/animation/old_animation/simple_idle_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
A simple example of an animated plot using a wx backend
"""
from __future__ import print_function
import time
import numpy as np
import matplotlib
matplotlib.use('WXAgg') # do this before importing pylab

import matplotlib.pyplot as plt

fig = plt.figure()

ax = fig.add_subplot(111)
fig, ax = plt.subplots()
t = np.arange(0, 2*np.pi, 0.1)
line, = ax.plot(t, np.sin(t))
dt = 0.05
Expand Down
5 changes: 1 addition & 4 deletions examples/animation/old_animation/simple_timer_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
"""
A simple example of an animated plot using a wx backend
"""
import time
import numpy as np
import matplotlib
matplotlib.use('WXAgg') # do this before importing pylab

import matplotlib.pyplot as plt

fig = plt.figure()

ax = fig.add_subplot(111)
fig, ax = plt.subplots()
t = np.arange(0, 2*np.pi, 0.1)
line, = ax.plot(t, np.sin(t))
dt = 0.05
Expand Down
8 changes: 3 additions & 5 deletions examples/animation/old_animation/strip_chart_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import matplotlib
matplotlib.use('GTKAgg')
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D


Expand Down Expand Up @@ -62,11 +63,8 @@ def update(self, *args):
return True


from pylab import figure, show

fig = figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
scope = Scope(ax)
gobject.idle_add(scope.update)

show()
plt.show()
3 changes: 1 addition & 2 deletions examples/animation/random_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
line, = ax.plot(np.random.rand(10))
ax.set_ylim(0, 1)

Expand Down
3 changes: 1 addition & 2 deletions examples/animation/simple_anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()

x = np.arange(0, 2*np.pi, 0.01) # x-array
line, = ax.plot(x, np.sin(x))
Expand Down
4 changes: 1 addition & 3 deletions examples/animation/strip_chart_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Emulate an oscilloscope. Requires the animation API introduced in
matplotlib 1.0 SVN.
"""
import matplotlib
import numpy as np
from matplotlib.lines import Line2D
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -44,8 +43,7 @@ def emitter(p=0.03):
else:
yield np.random.rand(1)

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
scope = Scope(ax)

# pass a generator in "emitter" to produce data for the update func
Expand Down
3 changes: 1 addition & 2 deletions examples/api/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ A simple example of the recommended style is::
import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111) # or add_axes
fig, ax = plt.subplots()
ax.plot(np.random.rand(10))
ax.set_xlabel('some x data')
ax.set_ylabel('some y data')
Expand Down
3 changes: 1 addition & 2 deletions examples/api/barchart_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)

womenMeans = (25, 32, 34, 20, 25)
Expand Down
Loading