Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit9a84637

Browse files
Merge pull request#2 from matplotlib/master
doc
2 parents539d8b8 +2208665 commit9a84637

File tree

3 files changed

+50
-94
lines changed

3 files changed

+50
-94
lines changed

‎examples/animation/random_walk.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,29 @@
77

88
importnumpyasnp
99
importmatplotlib.pyplotasplt
10-
importmpl_toolkits.mplot3d.axes3dasp3
1110
importmatplotlib.animationasanimation
1211

1312
# Fixing random state for reproducibility
1413
np.random.seed(19680801)
1514

1615

17-
defGen_RandLine(length,dims=2):
16+
defgen_rand_line(length,dims=2):
1817
"""
1918
Create a line using a random walk algorithm
2019
2120
length is the number of points for the line.
2221
dims is the number of dimensions the line has.
2322
"""
24-
lineData=np.empty((dims,length))
25-
lineData[:,0]=np.random.rand(dims)
23+
line_data=np.empty((dims,length))
24+
line_data[:,0]=np.random.rand(dims)
2625
forindexinrange(1,length):
2726
# scaling the random numbers by 0.1 so
2827
# movement is small compared to position.
2928
# subtraction by 0.5 is to change the range to [-0.5, 0.5]
3029
# to allow a line to move backwards.
31-
step= ((np.random.rand(dims)-0.5)*0.1)
32-
lineData[:,index]=lineData[:,index-1]+step
33-
34-
returnlineData
30+
step= (np.random.rand(dims)-0.5)*0.1
31+
line_data[:,index]=line_data[:,index-1]+step
32+
returnline_data
3533

3634

3735
defupdate_lines(num,dataLines,lines):
@@ -41,12 +39,13 @@ def update_lines(num, dataLines, lines):
4139
line.set_3d_properties(data[2, :num])
4240
returnlines
4341

42+
4443
# Attaching 3D axis to the figure
4544
fig=plt.figure()
46-
ax=p3.Axes3D(fig)
45+
ax=fig.add_subplot(projection="3d")
4746

4847
# Fifty lines of random 3-D lines
49-
data= [Gen_RandLine(25,3)forindexinrange(50)]
48+
data= [gen_rand_line(25,3)forindexinrange(50)]
5049

5150
# Creating fifty line objects.
5251
# NOTE: Can't pass empty arrays into 3d version of plot()
@@ -65,7 +64,7 @@ def update_lines(num, dataLines, lines):
6564
ax.set_title('3D Test')
6665

6766
# Creating the Animation object
68-
line_ani=animation.FuncAnimation(fig,update_lines,25,fargs=(data,lines),
69-
interval=50,blit=False)
67+
line_ani=animation.FuncAnimation(
68+
fig,update_lines,25,fargs=(data,lines),interval=50)
7069

7170
plt.show()

‎lib/matplotlib/units.py

Lines changed: 30 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ class ConversionError(TypeError):
5555

5656
classAxisInfo(object):
5757
"""
58-
Information to support default axis labeling, tick labeling, and
59-
default limits. An instance of this class must be returned by
60-
:meth:`ConversionInterface.axisinfo`.
58+
Information to support default axis labeling, tick labeling, and limits.
59+
60+
An instance of this class must be returned by
61+
`ConversionInterface.axisinfo`.
6162
"""
6263
def__init__(self,majloc=None,minloc=None,
6364
majfmt=None,minfmt=None,label=None,
@@ -96,8 +97,7 @@ class ConversionInterface(object):
9697
@staticmethod
9798
defaxisinfo(unit,axis):
9899
"""
99-
Return an `~units.AxisInfo` instance for the axis with the
100-
specified units.
100+
Return an `~units.AxisInfo` for the axis with the specified units.
101101
"""
102102
returnNone
103103

@@ -112,19 +112,19 @@ def default_units(x, axis):
112112
defconvert(obj,unit,axis):
113113
"""
114114
Convert *obj* using *unit* for the specified *axis*.
115-
If *obj* is a sequence, return the converted sequence.
116-
The output must bea sequence of scalars that can be used by the numpy
117-
array layer.
115+
116+
If *obj* isa sequence, return the converted sequence. The output must
117+
be a sequence of scalars that can be used by the numpyarray layer.
118118
"""
119119
returnobj
120120

121121
@staticmethod
122122
defis_numlike(x):
123123
"""
124-
The Matplotlib datalim, autoscaling, locators etc work with
125-
scalarswhich are the units converted to floats given the
126-
current unit. Theconverter may be passed these floats, or
127-
arrays of them, even whenunits are set.
124+
The Matplotlib datalim, autoscaling, locators etc work with scalars
125+
which are the units converted to floats given the current unit. The
126+
converter may be passed these floats, or arrays of them, even when
127+
units are set.
128128
"""
129129
ifnp.iterable(x):
130130
forthisxinx:
@@ -134,73 +134,33 @@ def is_numlike(x):
134134

135135

136136
classRegistry(dict):
137-
"""
138-
A register that maps types to conversion interfaces.
139-
"""
140-
def__init__(self):
141-
dict.__init__(self)
142-
self._cached= {}
137+
"""Register types with conversion interface."""
143138

144139
defget_converter(self,x):
145-
"""
146-
Get the converter for data that has the same type as *x*. If no
147-
converters are registered for *x*, returns ``None``.
148-
"""
149-
150-
ifnotlen(self):
151-
returnNone# nothing registered
152-
# DISABLED idx = id(x)
153-
# DISABLED cached = self._cached.get(idx)
154-
# DISABLED if cached is not None: return cached
155-
156-
converter=None
157-
classx=getattr(x,'__class__',None)
158-
159-
ifclassxisnotNone:
160-
converter=self.get(classx)
161-
162-
ifconverterisNoneandhasattr(x,"values"):
163-
# this unpacks pandas series or dataframes...
164-
x=x.values
165-
166-
# If x is an array, look inside the array for data with units
140+
"""Get the converter interface instance for *x*, or None."""
141+
ifhasattr(x,"values"):
142+
x=x.values# Unpack pandas Series and DataFrames.
167143
ifisinstance(x,np.ndarray):
144+
# In case x in a masked array, access the underlying data (only its
145+
# type matters). If x is a regular ndarray, getdata() just returns
146+
# the array itself.
147+
x=np.ma.getdata(x).ravel()
168148
# If there are no elements in x, infer the units from its dtype
169149
ifnotx.size:
170150
returnself.get_converter(np.array([0],dtype=x.dtype))
171-
xravel=x.ravel()
172-
try:
173-
# pass the first value of x that is not masked back to
174-
# get_converter
175-
ifnotnp.all(xravel.mask):
176-
# Get first non-masked item
177-
converter=self.get_converter(
178-
xravel[np.argmin(xravel.mask)])
179-
returnconverter
180-
exceptAttributeError:
181-
# not a masked_array
182-
# Make sure we don't recurse forever -- it's possible for
183-
# ndarray subclasses to continue to return subclasses and
184-
# not ever return a non-subclass for a single element.
185-
next_item=xravel[0]
186-
if (notisinstance(next_item,np.ndarray)or
187-
next_item.shape!=x.shape):
188-
converter=self.get_converter(next_item)
189-
returnconverter
190-
191-
# If we haven't found a converter yet, try to get the first element
192-
ifconverterisNone:
193-
try:
194-
thisx=cbook.safe_first_element(x)
151+
try:# Look up in the cache.
152+
returnself[type(x)]
153+
exceptKeyError:
154+
try:# If cache lookup fails, look up based on first element...
155+
first=cbook.safe_first_element(x)
195156
except (TypeError,StopIteration):
196157
pass
197158
else:
198-
ifclassxandclassx!=getattr(thisx,'__class__',None):
199-
converter=self.get_converter(thisx)
200-
returnconverter
201-
202-
# DISABLED self._cached[idx] = converter
203-
returnconverter
159+
# ... and avoid infinite recursion for pathological iterables
160+
# where indexing returns instances of the same iterable class.
161+
iftype(first)isnottype(x):
162+
returnself.get_converter(first)
163+
returnNone
204164

205165

206166
registry=Registry()

‎tutorials/toolkits/mplot3d.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,21 @@
1414
1515
Getting started
1616
---------------
17-
An Axes3D object is created just like any other axes using
18-
the projection='3d' keyword.
19-
Create a new :class:`matplotlib.figure.Figure` and
20-
add a new axes to it of type :class:`~mpl_toolkits.mplot3d.Axes3D`::
17+
3D Axes (of class `Axes3D`) are created by passing the ``projection="3d"``
18+
keyword argument to `Figure.add_subplot`::
2119
2220
import matplotlib.pyplot as plt
23-
from mpl_toolkits.mplot3d import Axes3D
2421
fig = plt.figure()
2522
ax = fig.add_subplot(111, projection='3d')
2623
27-
.. versionadded:: 1.0.0
28-
This approach is the preferred method of creating a 3D axes.
24+
.. versionchanged:: 1.0.0
25+
Prior to Matplotlib 1.0.0, `Axes3D` needed to be directly instantiated with
26+
``from mpl_toolkits.mplot3d import Axes3D; ax = Axes3D(fig)``.
2927
30-
.. note::
31-
Prior to version 1.0.0, the method of creating a 3D axes was
32-
different. For those using older versions of matplotlib, change
33-
``ax = fig.add_subplot(111, projection='3d')``
34-
to ``ax = Axes3D(fig)``.
28+
.. versionchanged:: 3.2.0
29+
Prior to Matplotlib 3.2.0, it was necessary to explicitly import the
30+
:mod:`mpl_toolkits.mplot3d` module to make the '3d' projection to
31+
`Figure.add_subplot`.
3532
3633
See the :ref:`toolkit_mplot3d-faq` for more information about the mplot3d
3734
toolkit.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp