Skip to content

Commit fdb66ae

Browse files
author
Dvij
committed
1 parent adf4666 commit fdb66ae

1 file changed

Lines changed: 48 additions & 8 deletions

File tree

‎lib/matplotlib/pyplot.py‎

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
# We may not need the following imports here:
5454
from matplotlib.colors import Normalize
55+
from matplotlib.colors import normalize # for backwards compat.
5556
from matplotlib.lines import Line2D
5657
from matplotlib.text import Text, Annotation
5758
from matplotlib.patches import Polygon, Rectangle, Circle, Arrow
@@ -170,6 +171,46 @@ def ion():
170171
'Turn interactive mode on.'
171172
matplotlib.interactive(True)
172173

174+
def pickle_save(obj, f=None, protocol=0):
175+
"""
176+
Write a pickled representation of obj as a string or a file depending on the number and type of arguments used.
177+
178+
``pickle_save(obj, file, protocol)`` Write a pickled representation of obj to the open file object file.
179+
180+
``pickle_save(obj, protocol)`` Return the pickled representation of the object as a string, instead of writing it to a file.
181+
"""
182+
import pickle
183+
184+
if not f:
185+
return pickle.dumps(obj, protocol)
186+
187+
pickle.dump(obj, f, protocol)
188+
189+
def pickle_load(*args, **kwargs):
190+
"""
191+
Read a string or pickled object and reconstruct the original object hierarchy.
192+
193+
``pickle_load(file)`` Read a string from the open file object file and interpret it as a pickle data stream, reconstructing and returning the original object hierarchy.
194+
195+
``pick_load(str)`` Read a pickled object hierarchy from a string. Characters in the string past the pickled object’s representation are ignored.
196+
197+
"""
198+
import pickle
199+
200+
state = isinteractive()
201+
if state:
202+
ioff()
203+
if len(args) != 1 or not(isinstance(args[0], str) or isinstance(args[0], file)):
204+
warnings.warn('Unsupported number/type of argument(s).')
205+
if isinstance(args[0], str):
206+
unpickledobj = pickle.loads(args[0])
207+
if state:
208+
ion()
209+
return unpickledobj
210+
211+
pickle.load(args[0])
212+
if state:
213+
ion()
173214

174215
def pause(interval):
175216
"""
@@ -452,7 +493,7 @@ def make_active(event):
452493

453494

454495
def gcf():
455-
"Get a reference to the current figure."
496+
"Return a reference to the current figure."
456497

457498
figManager = _pylab_helpers.Gcf.get_active()
458499
if figManager is not None:
@@ -808,12 +849,12 @@ def sca(ax):
808849

809850
def gca(**kwargs):
810851
"""
811-
Get the current :class:`~matplotlib.axes.Axes` instance on the
852+
Return the current :class:`~matplotlib.axes.Axes` instance on the
812853
current figure matching the given keyword args, or create one.
813854
814855
Examples
815856
---------
816-
To get the current polar axes on the current figure::
857+
To get the the current polar axes on the current figure::
817858
818859
plt.gca(projection='polar')
819860
@@ -1160,7 +1201,7 @@ def subplot2grid(shape, loc, rowspan=1, colspan=1, **kwargs):
11601201
11611202
is identical to ::
11621203
1163-
gridspec=GridSpec(shape[0], shape[1])
1204+
gridspec=GridSpec(shape[0], shape[2])
11641205
subplotspec=gridspec.new_subplotspec(loc, rowspan, colspan)
11651206
subplot(subplotspec)
11661207
"""
@@ -2181,7 +2222,7 @@ def clim(vmin=None, vmax=None):
21812222
"""
21822223
im = gci()
21832224
if im is None:
2184-
raise RuntimeError('You must first define an image, e.g., with imshow')
2225+
raise RuntimeError('You must first define an image, eg with imshow')
21852226

21862227
im.set_clim(vmin, vmax)
21872228
draw_if_interactive()
@@ -3065,7 +3106,7 @@ def phase_spectrum(x, Fs=None, Fc=None, window=None, pad_to=None, sides=None,
30653106
def pie(x, explode=None, labels=None, colors=None, autopct=None,
30663107
pctdistance=0.6, shadow=False, labeldistance=1.1, startangle=None,
30673108
radius=None, counterclock=True, wedgeprops=None, textprops=None,
3068-
center=(0, 0), frame=False, hold=None):
3109+
hold=None):
30693110
ax = gca()
30703111
# allow callers to override the hold state by passing hold=True|False
30713112
washold = ax.ishold()
@@ -3077,8 +3118,7 @@ def pie(x, explode=None, labels=None, colors=None, autopct=None,
30773118
autopct=autopct, pctdistance=pctdistance, shadow=shadow,
30783119
labeldistance=labeldistance, startangle=startangle,
30793120
radius=radius, counterclock=counterclock,
3080-
wedgeprops=wedgeprops, textprops=textprops, center=center,
3081-
frame=frame)
3121+
wedgeprops=wedgeprops, textprops=textprops)
30823122
draw_if_interactive()
30833123
finally:
30843124
ax.hold(washold)

0 commit comments

Comments
 (0)