Skip to content

Commit 2ceea35

Browse files
committed
Merge remote-tracking branch 'matplotlib/v2.x'
Conflicts: examples/mplot3d/polys3d_demo.py lib/matplotlib/colors.py Both of these conflicts are due to backporting the rgba improvements to 2.x. Kept the master-branch version in both cases.
2 parents 9e228e6 + 7a268b9 commit 2ceea35

File tree

10 files changed

+125
-98
lines changed

10 files changed

+125
-98
lines changed

lib/matplotlib/animation.py

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,14 @@ def grab_frame(self, **savefig_kwargs):
305305
# frame format and dpi.
306306
self.fig.savefig(self._frame_sink(), format=self.frame_format,
307307
dpi=self.dpi, **savefig_kwargs)
308-
except RuntimeError:
308+
except (RuntimeError, IOError) as e:
309309
out, err = self._proc.communicate()
310310
verbose.report('MovieWriter -- Error '
311311
'running proc:\n%s\n%s' % (out,
312312
err), level='helpful')
313-
raise
313+
raise IOError('Error saving animation to file (cause: {0}) '
314+
'Stdout: {1} StdError: {2}. It may help to re-run '
315+
'with --verbose-debug.'.format(e, out, err))
314316

315317
def _frame_sink(self):
316318
'Returns the place to which frames should be written.'
@@ -787,13 +789,28 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
787789
'mencoder'. If nothing is passed, the value of the rcparam
788790
`animation.writer` is used.
789791
792+
*dpi* controls the dots per inch for the movie frames. This combined
793+
with the figure's size in inches controls the size of the movie.
794+
795+
*savefig_kwargs* is a dictionary containing keyword arguments to be
796+
passed on to the 'savefig' command which is called repeatedly to save
797+
the individual frames. This can be used to set tight bounding boxes,
798+
for example.
799+
800+
*extra_anim* is a list of additional `Animation` objects that should
801+
be included in the saved movie file. These need to be from the same
802+
`matplotlib.Figure` instance. Also, animation frames will just be
803+
simply combined, so there should be a 1:1 correspondence between
804+
the frames from the different animations.
805+
806+
These remaining arguments are used to construct a :class:`MovieWriter`
807+
instance when necessary and are only considered valid if *writer* is
808+
not a :class:`MovieWriter` instance.
809+
790810
*fps* is the frames per second in the movie. Defaults to None,
791811
which will use the animation's specified interval to set the frames
792812
per second.
793813
794-
*dpi* controls the dots per inch for the movie frames. This combined
795-
with the figure's size in inches controls the size of the movie.
796-
797814
*codec* is the video codec to be used. Not all codecs are supported
798815
by a given :class:`MovieWriter`. If none is given, this defaults to the
799816
value specified by the rcparam `animation.codec`.
@@ -811,18 +828,21 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
811828
*metadata* is a dictionary of keys and values for metadata to include
812829
in the output file. Some keys that may be of use include:
813830
title, artist, genre, subject, copyright, srcform, comment.
814-
815-
*extra_anim* is a list of additional `Animation` objects that should
816-
be included in the saved movie file. These need to be from the same
817-
`matplotlib.Figure` instance. Also, animation frames will just be
818-
simply combined, so there should be a 1:1 correspondence between
819-
the frames from the different animations.
820-
821-
*savefig_kwargs* is a dictionary containing keyword arguments to be
822-
passed on to the 'savefig' command which is called repeatedly to save
823-
the individual frames. This can be used to set tight bounding boxes,
824-
for example.
825831
'''
832+
# If the writer is None, use the rc param to find the name of the one
833+
# to use
834+
if writer is None:
835+
writer = rcParams['animation.writer']
836+
elif (not is_string_like(writer) and
837+
any(arg is not None
838+
for arg in (fps, codec, bitrate, extra_args, metadata))):
839+
raise RuntimeError('Passing in values for arguments for arguments '
840+
'fps, codec, bitrate, extra_args, or metadata '
841+
'is not supported when writer is an existing '
842+
'MovieWriter instance. These should instead be '
843+
'passed as arguments when creating the '
844+
'MovieWriter instance.')
845+
826846
if savefig_kwargs is None:
827847
savefig_kwargs = {}
828848

@@ -838,11 +858,6 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
838858
# Convert interval in ms to frames per second
839859
fps = 1000. / self._interval
840860

841-
# If the writer is None, use the rc param to find the name of the one
842-
# to use
843-
if writer is None:
844-
writer = rcParams['animation.writer']
845-
846861
# Re-use the savefig DPI for ours if none is given
847862
if dpi is None:
848863
dpi = rcParams['savefig.dpi']

lib/matplotlib/tests/test_path.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def test_contains_points_negative_radius():
3939
expected = [True, False, False]
4040
result = path.contains_points(points, radius=-0.5)
4141

42-
assert result.dtype == np.bool
4342
assert np.all(result == expected)
4443

4544

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,7 +2242,9 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True,
22422242
that *c* should not be a single numeric RGB or RGBA
22432243
sequence because that is indistinguishable from an array
22442244
of values to be colormapped. *c* can be a 2-D array in
2245-
which the rows are RGB or RGBA, however.
2245+
which the rows are RGB or RGBA, however, including the
2246+
case of a single row to specify the same color for
2247+
all points.
22462248
22472249
*depthshade*
22482250
Whether or not to shade the scatter markers to give
@@ -2271,15 +2273,15 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True,
22712273

22722274
s = np.ma.ravel(s) # This doesn't have to match x, y in size.
22732275

2274-
if c is None:
2275-
c = self._get_lines.get_next_color()
2276-
cstr = cbook.is_string_like(c) or cbook.is_sequence_of_strings(c)
2277-
if not cstr:
2278-
c = np.asanyarray(c)
2279-
if c.size == xs.size:
2280-
c = np.ma.ravel(c)
2281-
2282-
xs, ys, zs, s, c = cbook.delete_masked_points(xs, ys, zs, s, c)
2276+
if c is not None:
2277+
cstr = cbook.is_string_like(c) or cbook.is_sequence_of_strings(c)
2278+
if not cstr:
2279+
c = np.asanyarray(c)
2280+
if c.size == xs.size:
2281+
c = np.ma.ravel(c)
2282+
xs, ys, zs, s, c = cbook.delete_masked_points(xs, ys, zs, s, c)
2283+
else:
2284+
xs, ys, zs, s = cbook.delete_masked_points(xs, ys, zs, s)
22832285

22842286
patches = Axes.scatter(self, xs, ys, s=s, c=c, *args, **kwargs)
22852287
if not cbook.iterable(zs):

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ def test_scatter3d():
110110
c='b', marker='^')
111111

112112

113+
@image_comparison(baseline_images=['scatter3d_color'], remove_text=True,
114+
extensions=['png'])
115+
def test_scatter3d_color():
116+
fig = plt.figure()
117+
ax = fig.add_subplot(111, projection='3d')
118+
ax.scatter(np.arange(10), np.arange(10), np.arange(10),
119+
color='r', marker='o')
120+
ax.scatter(np.arange(10, 20), np.arange(10, 20), np.arange(10, 20),
121+
color='b', marker='s')
122+
123+
113124
@image_comparison(baseline_images=['surface3d'], remove_text=True)
114125
def test_surface3d():
115126
fig = plt.figure()

src/_backend_agg.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -956,13 +956,13 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
956956
typename PathGenerator::path_iterator path = path_generator(i);
957957

958958
if (Ntransforms) {
959-
typename TransformArray::sub_t subtrans = transforms[i % Ntransforms];
960-
trans = agg::trans_affine(subtrans(0, 0),
961-
subtrans(1, 0),
962-
subtrans(0, 1),
963-
subtrans(1, 1),
964-
subtrans(0, 2),
965-
subtrans(1, 2));
959+
int it = i % Ntransforms;
960+
trans = agg::trans_affine(transforms(it, 0, 0),
961+
transforms(it, 1, 0),
962+
transforms(it, 0, 1),
963+
transforms(it, 1, 1),
964+
transforms(it, 0, 2),
965+
transforms(it, 1, 2));
966966
trans *= master_transform;
967967
} else {
968968
trans = master_transform;
@@ -984,13 +984,13 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
984984
trans *= agg::trans_affine_translation(0.0, (double)height);
985985

986986
if (Nfacecolors) {
987-
typename ColorArray::sub_t facecolor = facecolors[i % Nfacecolors];
988-
face.second = agg::rgba(facecolor(0), facecolor(1), facecolor(2), facecolor(3));
987+
int ic = i % Nfacecolors;
988+
face.second = agg::rgba(facecolors(ic, 0), facecolors(ic, 1), facecolors(ic, 2), facecolors(ic, 3));
989989
}
990990

991991
if (Nedgecolors) {
992-
typename ColorArray::sub_t edgecolor = edgecolors[i % Nedgecolors];
993-
gc.color = agg::rgba(edgecolor(0), edgecolor(1), edgecolor(2), edgecolor(3));
992+
int ic = i % Nedgecolors;
993+
gc.color = agg::rgba(edgecolors(ic, 0), edgecolors(ic, 1), edgecolors(ic, 2), edgecolors(ic, 3));
994994

995995
if (Nlinewidths) {
996996
gc.linewidth = linewidths(i % Nlinewidths);
@@ -1269,8 +1269,8 @@ inline void RendererAgg::draw_gouraud_triangles(GCAgg &gc,
12691269
bool has_clippath = render_clippath(gc.clippath.path, gc.clippath.trans);
12701270

12711271
for (int i = 0; i < points.dim(0); ++i) {
1272-
typename PointArray::sub_t point = points[i];
1273-
typename ColorArray::sub_t color = colors[i];
1272+
typename PointArray::sub_t point = points.subarray(i);
1273+
typename ColorArray::sub_t color = colors.subarray(i);
12741274

12751275
_draw_gouraud_triangle(point, color, trans, has_clippath);
12761276
}

src/_image.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,12 @@ void pcolor(CoordinateArray &x,
120120
a10 = (1.0 - alpha) * beta;
121121
a11 = 1.0 - a00 - a01 - a10;
122122

123-
typename ColorArray::sub_t::sub_t start00 = d[rowstart[i]][colstart[j]];
124-
typename ColorArray::sub_t::sub_t start01 = d[rowstart[i]][colstart[j] + 1];
125-
typename ColorArray::sub_t::sub_t start10 = d[rowstart[i] + 1][colstart[j]];
126-
typename ColorArray::sub_t::sub_t start11 = d[rowstart[i] + 1][colstart[j] + 1];
127123
for (size_t k = 0; k < 4; ++k) {
128124
position[k] =
129-
start00(k) * a00 + start01(k) * a01 + start10(k) * a10 + start11(k) * a11;
125+
d(rowstart[i], colstart[j], k) * a00 +
126+
d(rowstart[i], colstart[j] + 1, k) * a01 +
127+
d(rowstart[i] + 1, colstart[j], k) * a10 +
128+
d(rowstart[i] + 1, colstart[j] + 1, k) * a11;
130129
}
131130
position += 4;
132131
}

0 commit comments

Comments
 (0)