Skip to content

Backport #5307 to v2.0.x #5652

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

Merged
merged 1 commit into from
Dec 13, 2015
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion examples/api/custom_projection_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def __init__(self, round_to=1.0):
self._round_to = round_to

def __call__(self, x, pos=None):
degrees = round(np.degrees(x) / self._round_to) * self._round_to
degrees = np.round(np.degrees(x) / self._round_to) * self._round_to
# \u00b0 : degree symbol
return "%d\u00b0" % degrees

Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,7 @@ def tk_window_focus():
'matplotlib.tests.test_contour',
'matplotlib.tests.test_dates',
'matplotlib.tests.test_delaunay',
'matplotlib.tests.test_dviread',
'matplotlib.tests.test_figure',
'matplotlib.tests.test_font_manager',
'matplotlib.tests.test_gridspec',
Expand Down Expand Up @@ -1473,6 +1474,7 @@ def tk_window_focus():
'matplotlib.tests.test_tightlayout',
'matplotlib.tests.test_transforms',
'matplotlib.tests.test_triangulation',
'matplotlib.tests.test_type1font',
'matplotlib.tests.test_units',
'matplotlib.tests.test_widgets',
'matplotlib.tests.test_cycles',
Expand Down
15 changes: 8 additions & 7 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from matplotlib.externals import six
from matplotlib.externals.six.moves import xrange

from collections import OrderedDict
import itertools
import warnings
import math
Expand Down Expand Up @@ -903,11 +904,11 @@ def _gen_axes_spines(self, locations=None, offset=0.0, units='inches'):
Intended to be overridden by new projection types.

"""
return {
'left': mspines.Spine.linear_spine(self, 'left'),
'right': mspines.Spine.linear_spine(self, 'right'),
'bottom': mspines.Spine.linear_spine(self, 'bottom'),
'top': mspines.Spine.linear_spine(self, 'top'), }
return OrderedDict([
('left', mspines.Spine.linear_spine(self, 'left')),
('right', mspines.Spine.linear_spine(self, 'right')),
('bottom', mspines.Spine.linear_spine(self, 'bottom')),
('top', mspines.Spine.linear_spine(self, 'top'))])

def cla(self):
"""Clear the current axes."""
Expand Down Expand Up @@ -2341,8 +2342,8 @@ def draw(self, renderer=None, inframe=False):
for z, im in zorder_images]

l, b, r, t = self.bbox.extents
width = int(mag * ((round(r) + 0.5) - (round(l) - 0.5)))
height = int(mag * ((round(t) + 0.5) - (round(b) - 0.5)))
width = int(mag * ((np.round(r) + 0.5) - (np.round(l) - 0.5)))
height = int(mag * ((np.round(t) + 0.5) - (np.round(b) - 0.5)))
im = mimage.from_images(height,
width,
ims)
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):

xd = descent * sin(radians(angle))
yd = descent * cos(radians(angle))
x = round(x + ox + xd)
y = round(y - oy + yd)
x = np.round(x + ox + xd)
y = np.round(y - oy + yd)
self._renderer.draw_text_image(font_image, x, y + 1, angle, gc)

def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def set_clip_rectangle(self, rectangle):
if not rectangle: return
x,y,w,h = rectangle.bounds
# pixel-aligned clip-regions are faster
x,y,w,h = round(x), round(y), round(w), round(h)
x,y,w,h = np.round(x), np.round(y), np.round(w), np.round(h)
ctx = self.ctx
ctx.new_path()
ctx.rectangle (x, self.renderer.height - h - y, w, h)
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/backends/backend_gdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def draw_path(self, gc, path, transform, rgbFace=None):
for polygon in polygons:
# draw_polygon won't take an arbitrary sequence -- it must be a list
# of tuples
polygon = [(int(round(x)), int(round(y))) for x, y in polygon]
polygon = [(int(np.round(x)), int(np.round(y))) for x, y in polygon]
if rgbFace is not None:
saveColor = gc.gdkGC.foreground
gc.gdkGC.foreground = gc.rgb_to_gdk_color(rgbFace)
Expand Down Expand Up @@ -281,7 +281,7 @@ def _get_pango_layout(self, s, prop):
return value

size = prop.get_size_in_points() * self.dpi / 96.0
size = round(size)
size = np.round(size)

font_str = '%s, %s %i' % (prop.get_name(), prop.get_style(), size,)
font = pango.FontDescription(font_str)
Expand Down Expand Up @@ -387,7 +387,7 @@ def set_dashes(self, dash_offset, dash_list):
self.gdkGC.line_style = gdk.LINE_SOLID
else:
pixels = self.renderer.points_to_pixels(np.asarray(dash_list))
dl = [max(1, int(round(val))) for val in pixels]
dl = [max(1, int(np.round(val))) for val in pixels]
self.gdkGC.set_dashes(dash_offset, dl)
self.gdkGC.line_style = gdk.LINE_ON_OFF_DASH

Expand All @@ -413,7 +413,7 @@ def set_linewidth(self, w):
self.gdkGC.line_width = 0
else:
pixels = self.renderer.points_to_pixels(w)
self.gdkGC.line_width = max(1, int(round(pixels)))
self.gdkGC.line_width = max(1, int(np.round(pixels)))


def new_figure_manager(num, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ def cvt(length, upe=font.units_per_EM, nearest=True):
"Convert font coordinates to PDF glyph coordinates"
value = length / upe * 1000
if nearest:
return round(value)
return np.round(value)
# Perhaps best to round away from zero for bounding
# boxes and the like
if value < 0:
Expand Down
4 changes: 0 additions & 4 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,8 +1171,6 @@ def print_figure_impl():
print("%s translate"%_nums_to_str(xo, yo), file=fh)
if rotation: print("%d rotate"%rotation, file=fh)
print("%s clipbox"%_nums_to_str(width*72, height*72, 0, 0), file=fh)
# Disable any sort of miter limit
print("%s setmiterlimit" % 100000, file=fh)

# write the figure
content = self._pswriter.getvalue()
Expand Down Expand Up @@ -1322,8 +1320,6 @@ def write(self, *kl, **kwargs):
#print >>fh, "gsave"
print("%s translate"%_nums_to_str(xo, yo), file=fh)
print("%s clipbox"%_nums_to_str(width*72, height*72, 0, 0), file=fh)
# Disable any sort of miter limit
print("%d setmiterlimit" % 100000, file=fh)

# write the figure
print(self._pswriter.getvalue(), file=fh)
Expand Down
16 changes: 7 additions & 9 deletions lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from matplotlib.externals.six import unichr

import os, base64, tempfile, gzip, io, sys, codecs, re
from collections import OrderedDict

import numpy as np

Expand Down Expand Up @@ -271,15 +272,15 @@ def __init__(self, width, height, svgwriter, basename=None, image_dpi=72):
assert basename is not None
self.basename = basename
self._imaged = {}
self._clipd = {}
self._clipd = OrderedDict()
self._char_defs = {}
self._markers = {}
self._path_collection_id = 0
self._imaged = {}
self._hatchd = {}
self._hatchd = OrderedDict()
self._has_gouraud = False
self._n_gradients = 0
self._fonts = {}
self._fonts = OrderedDict()
self.mathtext_parser = MathTextParser('SVG')

RendererBase.__init__(self)
Expand All @@ -306,10 +307,7 @@ def _write_default_style(self):
writer = self.writer
default_style = generate_css({
'stroke-linejoin': 'round',
'stroke-linecap': 'butt',
# Disable the miter limit. 100000 seems to be close to
# the maximum that renderers support before breaking.
'stroke-miterlimit': '100000'})
'stroke-linecap': 'butt'})
writer.start('defs')
writer.start('style', type='text/css')
writer.data('*{%s}\n' % default_style)
Expand Down Expand Up @@ -1104,7 +1102,7 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):

# Sort the characters by font, and output one tspan for
# each
spans = {}
spans = OrderedDict()
for font, fontsize, thetext, new_x, new_y, metrics in svg_glyphs:
style = generate_css({
'font-size': short_float_fmt(fontsize) + 'px',
Expand All @@ -1120,7 +1118,7 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
fontset = self._fonts.setdefault(font.fname, set())
fontset.add(thetext)

for style, chars in list(six.iteritems(spans)):
for style, chars in six.iteritems(spans):
chars.sort()

same_y = True
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def __init__(self, t, fmt, tz=None):

def __call__(self, x, pos=0):
'Return the label for time *x* at position *pos*'
ind = int(round(x))
ind = int(np.round(x))
if ind >= len(self.t) or ind <= 0:
return ''

Expand Down
32 changes: 16 additions & 16 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,10 @@ def make_image(self, magnification=1.0):
im.apply_translation(tx, ty)

l, b, r, t = self.axes.bbox.extents
widthDisplay = ((round(r*magnification) + 0.5) -
(round(l*magnification) - 0.5))
heightDisplay = ((round(t*magnification) + 0.5) -
(round(b*magnification) - 0.5))
widthDisplay = ((np.round(r*magnification) + 0.5) -
(np.round(l*magnification) - 0.5))
heightDisplay = ((np.round(t*magnification) + 0.5) -
(np.round(b*magnification) - 0.5))

# resize viewport to display
rx = widthDisplay / numcols
Expand Down Expand Up @@ -773,8 +773,8 @@ def make_image(self, magnification=1.0):

x0, y0, v_width, v_height = self.axes.viewLim.bounds
l, b, r, t = self.axes.bbox.extents
width = (round(r) + 0.5) - (round(l) - 0.5)
height = (round(t) + 0.5) - (round(b) - 0.5)
width = (np.round(r) + 0.5) - (np.round(l) - 0.5)
height = (np.round(t) + 0.5) - (np.round(b) - 0.5)
width *= magnification
height *= magnification
im = _image.pcolor(self._Ax, self._Ay, A,
Expand Down Expand Up @@ -897,11 +897,11 @@ def make_image(self, magnification=1.0):
bg = mcolors.colorConverter.to_rgba(fc, 0)
bg = (np.array(bg)*255).astype(np.uint8)
l, b, r, t = self.axes.bbox.extents
width = (round(r) + 0.5) - (round(l) - 0.5)
height = (round(t) + 0.5) - (round(b) - 0.5)
width = (np.round(r) + 0.5) - (np.round(l) - 0.5)
height = (np.round(t) + 0.5) - (np.round(b) - 0.5)
# The extra cast-to-int is only needed for python2
width = int(round(width * magnification))
height = int(round(height * magnification))
width = int(np.round(width * magnification))
height = int(np.round(height * magnification))
if self._rgbacache is None:
A = self.to_rgba(self._A, bytes=True)
self._rgbacache = A
Expand Down Expand Up @@ -932,8 +932,8 @@ def draw(self, renderer, *args, **kwargs):
gc.set_clip_path(self.get_clip_path())
gc.set_alpha(self.get_alpha())
renderer.draw_image(gc,
round(self.axes.bbox.xmin),
round(self.axes.bbox.ymin),
np.round(self.axes.bbox.xmin),
np.round(self.axes.bbox.ymin),
im)
gc.restore()
self.stale = False
Expand Down Expand Up @@ -1093,7 +1093,7 @@ def draw(self, renderer, *args, **kwargs):
gc.set_clip_rectangle(self.figure.bbox)
gc.set_clip_path(self.get_clip_path())
gc.set_alpha(self.get_alpha())
renderer.draw_image(gc, round(self.ox), round(self.oy), im)
renderer.draw_image(gc, np.round(self.ox), np.round(self.oy), im)
gc.restore()
self.stale = False

Expand Down Expand Up @@ -1212,8 +1212,8 @@ def make_image(self, renderer, magnification=1.0):
im.set_resample(self._resample)

l, b, r, t = self.get_window_extent(renderer).extents # bbox.extents
widthDisplay = abs(round(r) - round(l))
heightDisplay = abs(round(t) - round(b))
widthDisplay = abs(np.round(r) - np.round(l))
heightDisplay = abs(np.round(t) - np.round(b))
widthDisplay *= magnification
heightDisplay *= magnification

Expand Down Expand Up @@ -1245,7 +1245,7 @@ def draw(self, renderer, *args, **kwargs):

l = np.min([x0, x1])
b = np.min([y0, y1])
renderer.draw_image(gc, round(l), round(b), im)
renderer.draw_image(gc, np.round(l), np.round(b), im)
gc.restore()
self.stale = True

Expand Down
9 changes: 5 additions & 4 deletions lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

import matplotlib.colors as mcolors
import matplotlib._png as _png

####################


Expand Down Expand Up @@ -2120,10 +2121,10 @@ def hlist_out(self, box):
if glue_sign == 1: # stretching
if glue_spec.stretch_order == glue_order:
cur_glue += glue_spec.stretch
cur_g = round(clamp(float(box.glue_set) * cur_glue))
cur_g = np.round(clamp(float(box.glue_set) * cur_glue))
elif glue_spec.shrink_order == glue_order:
cur_glue += glue_spec.shrink
cur_g = round(clamp(float(box.glue_set) * cur_glue))
cur_g = np.round(clamp(float(box.glue_set) * cur_glue))
rule_width += cur_g
self.cur_h += rule_width
self.cur_s -= 1
Expand Down Expand Up @@ -2176,10 +2177,10 @@ def vlist_out(self, box):
if glue_sign == 1: # stretching
if glue_spec.stretch_order == glue_order:
cur_glue += glue_spec.stretch
cur_g = round(clamp(float(box.glue_set) * cur_glue))
cur_g = np.round(clamp(float(box.glue_set) * cur_glue))
elif glue_spec.shrink_order == glue_order: # shrinking
cur_glue += glue_spec.shrink
cur_g = round(clamp(float(box.glue_set) * cur_glue))
cur_g = np.round(clamp(float(box.glue_set) * cur_glue))
rule_height += cur_g
self.cur_v += rule_height
elif isinstance(p, Char):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -2215,7 +2215,7 @@ def frange(xini, xfin=None, delta=None, **kw):
npts = kw['npts']
delta = (xfin-xini)/float(npts-endpoint)
except KeyError:
npts = int(round((xfin-xini)/delta)) + endpoint
npts = int(np.round((xfin-xini)/delta)) + endpoint
# round finds the nearest, so the endpoint can be up to
# delta/2 larger than xfin.

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/mpl-data/stylelib/classic.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ boxplot.flierprops.linestyle: none
boxplot.flierprops.linewidth: 1.0
boxplot.flierprops.marker: +
boxplot.flierprops.markeredgecolor: k
boxplot.flierprops.markerfacecolor: b
boxplot.flierprops.markerfacecolor: auto
boxplot.flierprops.markersize: 6.0
boxplot.meanline: False
boxplot.meanprops.color: r
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2291,9 +2291,9 @@ def _get_sawtooth_vertices(self, x0, y0, width, height, mutation_size):

# the sizes of the vertical and horizontal sawtooth are
# separately adjusted to fit the given box size.
dsx_n = int(round((width - tooth_size) / (tooth_size * 2))) * 2
dsx_n = int(np.round((width - tooth_size) / (tooth_size * 2))) * 2
dsx = (width - tooth_size) / dsx_n
dsy_n = int(round((height - tooth_size) / (tooth_size * 2))) * 2
dsy_n = int(np.round((height - tooth_size) / (tooth_size * 2))) * 2
dsy = (height - tooth_size) / dsy_n

x0, y0 = x0 - pad + tooth_size2, y0 - pad + tooth_size2
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/projections/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, round_to=1.0):

def __call__(self, x, pos=None):
degrees = (x / np.pi) * 180.0
degrees = round(degrees / self._round_to) * self._round_to
degrees = np.round(degrees / self._round_to) * self._round_to
if rcParams['text.usetex'] and not rcParams['text.latex.unicode']:
return r"$%0.0f^\circ$" % degrees
else:
Expand Down
8 changes: 7 additions & 1 deletion lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ def validate_color_or_inherit(s):
return validate_color(s)


def validate_color_or_auto(s):
if s == 'auto':
return s
return validate_color(s)


def validate_color(s):
'return a valid color arg'
try:
Expand Down Expand Up @@ -847,7 +853,7 @@ def validate_hist_bins(s):

'boxplot.flierprops.color': ['b', validate_color],
'boxplot.flierprops.marker': ['+', six.text_type],
'boxplot.flierprops.markerfacecolor': ['b', validate_color],
'boxplot.flierprops.markerfacecolor': ['auto', validate_color_or_auto],
'boxplot.flierprops.markeredgecolor': ['k', validate_color],
'boxplot.flierprops.markersize': [6, validate_float],
'boxplot.flierprops.linestyle': ['none', six.text_type],
Expand Down
Loading