8000 Make rounding behavior consistent by dopplershift · Pull Request #7573 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/api/api_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ CocoaAgg backend removed
~~~~~~~~~~~~~~~~~~~~~~~~
The deprecated and not fully functional CocoaAgg backend has been removed.

`round` removed from TkAgg Backend
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The TkAgg backend had its own implementation of the `round` function. This
was unused internally and has been removed. Instead, use either the
`round` builtin function or `numpy.round`.

'hold' functionality deprecated
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The 'hold' keyword argument and all functions and methods related
Expand Down
6 changes: 3 additions & 3 deletions examples/pylab_examples/date_index_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

from __future__ import print_function
import numpy
import numpy as np
from matplotlib.mlab import csv2rec
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
Expand All @@ -27,7 +27,7 @@ def __init__(self, dates, fmt='%Y-%m-%d'):

def __call__(self, x, pos=0):
'Return the label for time x at position pos'
ind = int(round(x))
ind = int(np.round(x))
Copy link
Member

Choose a reason for hiding this comment

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

Do you mind if I push to your branch to change the import of numpy to follow the standards?

if ind >= len(self.dates) or ind < 0:
return ''

Expand All @@ -37,6 +37,6 @@ def __call__(self, x, pos=0):

fig, ax = plt.subplots()
ax.xaxis.set_major_formatter(formatter)
ax.plot(numpy.arange(len(r)), r.close, 'o-')
ax.plot(np.arange(len(r)), r.close, 'o-')
fig.autofmt_xdate()
plt.show()
6 changes: 3 additions & 3 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):

#print x, y, int(x), int(y), s
self._renderer.draw_text_image(
font, round(x - xd + xo), round(y + yd + yo) + 1, angle, gc)
font, np.round(x - xd + xo), np.round(y + yd + yo) + 1, angle, gc)

def get_text_width_height_descent(self, s, prop, ismath):
"""
Expand Down Expand Up @@ -257,8 +257,8 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
w, h, d = self.get_text_width_height_descent(s, prop, ismath)
xd = d * sin(radians(angle))
yd = d * cos(radians(angle))
x = round(x + xd)
y = round(y + yd)
x = np.round(x + xd)
y = np.round(y + yd)

self._renderer.draw_text_image(Z, x, y, angle, gc)

Expand Down
3 changes: 0 additions & 3 deletions lib/matplotlib/backends/backend_tkagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@
}


def round(x):
return int(math.floor(x+0.5))

def raise_msg_to_str(msg):
"""msg is a return arg from a raise. Join with new lines"""
if not is_string_like(msg):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def flush_images():
gc = renderer.new_gc()
gc.set_clip_rectangle(parent.bbox)
gc.set_clip_path(parent.get_clip_path())
renderer.draw_image(gc, round(l), round(b), data)
renderer.draw_image(gc, np.round(l), np.round(b), data)
gc.restore()
del image_group[:]

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1760,8 +1760,8 @@ def _raw_ticks(self, vmin, vmax):
step = max(1, step)
best_vmin = (_vmin // step) * step

low = round(Base(step).le(_vmin - best_vmin) / step)
high = round(Base(step).ge(_vmax - best_vmin) / step)
low = np.round(Base(step).le(_vmin - best_vmin) / step)
high = np.round(Base(step).ge(_vmax - best_vmin) / step)
ticks = np.arange(low, high + 1) * step + best_vmin + offset
nticks = ((ticks <= vmax) & (ticks >= vmin)).sum()
if nticks >= self._min_n_ticks:
Expand Down
0