Skip to content

Commit

Permalink
Merge remote-tracking branch 'matplotlib/v2.0.x'
Browse files Browse the repository at this point in the history
 Conflicts:
	doc/users/pyplot_tutorial.rst
	examples/mplot3d/bars3d_demo.py
	examples/mplot3d/pathpatch3d.py
	examples/mplot3d/polys3d_demo.py
	examples/units/artist_tests.py
	  - kept master version
	examples/units/radian_demo.py
	  - merged changes
	examples/user_interfaces/svg_tooltip_sgskip.py
	  - white space
	lib/matplotlib/axes/_base.py
	  - white space
	lib/matplotlib/tests/test_animation.py
	  - kept master version
	lib/matplotlib/tests/test_axes.py
	  - kept master version
	lib/matplotlib/tests/test_figure.py
	  - kept new tests + fixed decorators
	lib/matplotlib/tests/test_legend.py
	  - kept new tests + fixed decorators
  • Loading branch information
tacaswell committed May 8, 2017
2 parents cffbf53 + 4308d39 commit 963faed
Show file tree
Hide file tree
Showing 16 changed files with 1,697 additions and 51 deletions.
565 changes: 555 additions & 10 deletions doc/users/github_stats.rst

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion examples/units/radian_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
Radian ticks
============
Plot using radian units.
Plot with radians from the basic_units mockup example package.
This example shows how the unit class can determine the tick locating,
formatting and axis labeling.
.. only:: builder_html
Expand Down
10 changes: 6 additions & 4 deletions examples/user_interfaces/svg_tooltip_sgskip.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@

for i, (item, label) in enumerate(zip(shapes, labels)):
patch = ax.add_patch(item)
annotate = ax.annotate(labels[i], xy=item.get_xy(), xytext=(0, 0),
textcoords='offset points', color='w', ha='center',
fontsize=8, bbox=dict(boxstyle='round, pad=.5', fc=(.1, .1, .1, .92),
ec=(1., 1., 1.), lw=1, zorder=1))
annotate = ax.annotate(labels[i], xy=item.get_xy(), xytext=(0, 0),
textcoords='offset points', color='w', ha='center',
fontsize=8, bbox=dict(boxstyle='round, pad=.5',
fc=(.1, .1, .1, .92),
ec=(1., 1., 1.), lw=1,
zorder=1))

ax.add_patch(patch)
patch.set_gid('mypatch_{:03d}'.format(i))
Expand Down
10 changes: 5 additions & 5 deletions extern/agg24-svn/include/agg_rendering_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace agg
m_stride = stride;
if(stride < 0)
{
m_start = m_buf - int(height - 1) * stride;
m_start = m_buf - (AGG_INT64)(height - 1) * stride;
}
}

Expand All @@ -80,10 +80,10 @@ namespace agg
//--------------------------------------------------------------------
AGG_INLINE T* row_ptr(int, int y, unsigned)
{
return m_start + y * m_stride;
return m_start + y * (AGG_INT64)m_stride;
}
AGG_INLINE T* row_ptr(int y) { return m_start + y * m_stride; }
AGG_INLINE const T* row_ptr(int y) const { return m_start + y * m_stride; }
AGG_INLINE T* row_ptr(int y) { return m_start + y * (AGG_INT64)m_stride; }
AGG_INLINE const T* row_ptr(int y) const { return m_start + y * (AGG_INT64)m_stride; }
AGG_INLINE row_data row (int y) const
{
return row_data(0, m_width-1, row_ptr(y));
Expand Down Expand Up @@ -181,7 +181,7 @@ namespace agg

if(stride < 0)
{
row_ptr = m_buf - int(height - 1) * stride;
row_ptr = m_buf - (AGG_INT64)(height - 1) * stride;
}

T** rows = &m_rows[0];
Expand Down
12 changes: 8 additions & 4 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2274,10 +2274,14 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval,
# ignore non-finite data limits if good limits exist
finite_dl = [d for d in dl if np.isfinite(d).all()]
if len(finite_dl):
# if finite limits exist for atleast one axis (and the other is infinite), restore the
# finite limits
x_finite = [d for d in dl if (np.isfinite(d.intervalx).all() and (d not in finite_dl))]
y_finite = [d for d in dl if (np.isfinite(d.intervaly).all() and (d not in finite_dl))]
# if finite limits exist for atleast one axis (and the
# other is infinite), restore the finite limits
x_finite = [d for d in dl
if (np.isfinite(d.intervalx).all() and
(d not in finite_dl))]
y_finite = [d for d in dl
if (np.isfinite(d.intervaly).all() and
(d not in finite_dl))]

dl = finite_dl
dl.extend(x_finite)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2106,7 +2106,7 @@ def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None,
dpi = rcParams['savefig.dpi']

if dpi == 'figure':
dpi = self.figure.dpi
dpi = getattr(self.figure, '_original_dpi', self.figure.dpi)

if facecolor is None:
facecolor = rcParams['savefig.facecolor']
Expand Down
33 changes: 22 additions & 11 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ def _create_qApp():
qApp = app

if is_pyqt5():
qApp.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
try:
qApp.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
qApp.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
except AttributeError:
pass


class Show(ShowBase):
Expand All @@ -158,6 +162,7 @@ def mainloop(self):
global qApp
qApp.exec_()


show = Show()


Expand Down Expand Up @@ -267,17 +272,20 @@ def leaveEvent(self, event):
FigureCanvasBase.leave_notify_event(self, guiEvent=event)

def mouseEventCoords(self, pos):
"""
Calculate mouse coordinates in logical pixels.
"""Calculate mouse coordinates in physical pixels
Qt5 use logical pixels, but the figure is scaled to physical
pixels for rendering. Transform to physical pixels so that
all of the down-stream transforms work as expected.
Also, the origin is different and needs to be corrected.
Qt5 and Matplotlib use logical pixels, but the figure is scaled to
physical pixels for rendering. Also, the origin is different and needs
to be corrected.
"""
dpi_ratio = self._dpi_ratio
x = pos.x()
# flip y so y=0 is bottom of canvas
y = self.figure.bbox.height / self._dpi_ratio - pos.y()
return x, y
y = self.figure.bbox.height / dpi_ratio - pos.y()
return x * dpi_ratio, y * dpi_ratio

def mousePressEvent(self, event):
x, y = self.mouseEventCoords(event.pos())
Expand Down Expand Up @@ -602,7 +610,10 @@ def __init__(self, canvas, parent, coordinates=True):
def _icon(self, name):
if is_pyqt5():
name = name.replace('.png', '_large.png')
return QtGui.QIcon(os.path.join(self.basedir, name))
pm = QtGui.QPixmap(os.path.join(self.basedir, name))
if hasattr(pm, 'setDevicePixelRatio'):
pm.setDevicePixelRatio(self.canvas._dpi_ratio)
return QtGui.QIcon(pm)

def _init_toolbar(self):
self.basedir = os.path.join(matplotlib.rcParams['datapath'], 'images')
Expand All @@ -612,7 +623,7 @@ def _init_toolbar(self):
self.addSeparator()
else:
a = self.addAction(self._icon(image_file + '.png'),
text, getattr(self, callback))
text, getattr(self, callback))
self._actions[callback] = a
if callback in ['zoom', 'pan']:
a.setCheckable(True)
Expand All @@ -634,7 +645,7 @@ def _init_toolbar(self):
QtCore.Qt.AlignRight | QtCore.Qt.AlignTop)
self.locLabel.setSizePolicy(
QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Ignored))
QtWidgets.QSizePolicy.Ignored))
labelAction = self.addWidget(self.locLabel)
labelAction.setVisible(True)

Expand Down
12 changes: 8 additions & 4 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
# compatible use the env variable.
QT_API = ETS[QT_API_ENV][0]

_fallback_to_qt4 = False
if QT_API is None:
# No ETS environment or incompatible so use rcParams.
if rcParams['backend'] == 'Qt5Agg':
Expand All @@ -87,7 +88,7 @@
# bindings is imported, but we still got here because a Qt
# related file was imported. This is allowed, fall back to Qt5
# using which ever binding the rparams ask for.

_fallback_to_qt4 = True
QT_API = rcParams['backend.qt5']

# We will define an appropriate wrapper for the differing versions
Expand Down Expand Up @@ -136,9 +137,12 @@
from PyQt5 import QtCore, QtGui, QtWidgets
_getSaveFileName = QtWidgets.QFileDialog.getSaveFileName
except ImportError:
# fell through, tried PyQt5, failed fall back to PyQt4
QT_API = rcParams['backend.qt4']
QT_RC_MAJOR_VERSION = 4
if _fallback_to_qt4:
# fell through, tried PyQt5, failed fall back to PyQt4
QT_API = rcParams['backend.qt4']
QT_RC_MAJOR_VERSION = 4
else:
raise

# needs to be if so we can re-test the value of QT_API which may
# have been changed in the above if block
Expand Down
22 changes: 13 additions & 9 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,10 @@ def __init__(self,
if frameon is None:
frameon = rcParams['figure.frameon']

self.dpi_scale_trans = Affine2D()
self.dpi = dpi
self.bbox_inches = Bbox.from_bounds(0, 0, *figsize)
self.dpi_scale_trans = Affine2D().scale(dpi, dpi)
# do not use property as it will trigger
self._dpi = dpi
self.bbox = TransformedBbox(self.bbox_inches, self.dpi_scale_trans)

self.frameon = frameon
Expand Down Expand Up @@ -415,6 +416,7 @@ def _get_dpi(self):
def _set_dpi(self, dpi):
self._dpi = dpi
self.dpi_scale_trans.clear().scale(dpi, dpi)
self.set_size_inches(*self.get_size_inches())
self.callbacks.process('dpi_changed', self)
dpi = property(_get_dpi, _set_dpi)

Expand Down Expand Up @@ -713,13 +715,15 @@ def set_size_inches(self, w, h=None, forward=True):
self.bbox_inches.p1 = w, h

if forward:
ratio = getattr(self.canvas, '_dpi_ratio', 1)
dpival = self.dpi / ratio
canvasw = w * dpival
canvash = h * dpival
manager = getattr(self.canvas, 'manager', None)
if manager is not None:
manager.resize(int(canvasw), int(canvash))
canvas = getattr(self, 'canvas')
if canvas is not None:
ratio = getattr(self.canvas, '_dpi_ratio', 1)
dpival = self.dpi / ratio
canvasw = w * dpival
canvash = h * dpival
manager = getattr(self.canvas, 'manager', None)
if manager is not None:
manager.resize(int(canvasw), int(canvash))
self.stale = True

def get_size_inches(self):
Expand Down
10 changes: 8 additions & 2 deletions lib/matplotlib/legend_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,8 @@ class HandlerPolyCollection(HandlerBase):
"""
def _update_prop(self, legend_handle, orig_handle):
def first_color(colors):
if colors is None:
return None
colors = mcolors.to_rgba_array(colors)
if len(colors):
return colors[0]
Expand All @@ -642,8 +644,12 @@ def get_first(prop_array):
return prop_array[0]
else:
return None
legend_handle.set_edgecolor(first_color(orig_handle.get_edgecolor()))
legend_handle.set_facecolor(first_color(orig_handle.get_facecolor()))
edgecolor = getattr(orig_handle, '_original_edgecolor',
orig_handle.get_edgecolor())
legend_handle.set_edgecolor(first_color(edgecolor))
facecolor = getattr(orig_handle, '_original_facecolor',
orig_handle.get_facecolor())
legend_handle.set_facecolor(first_color(facecolor))
legend_handle.set_fill(orig_handle.get_fill())
legend_handle.set_hatch(orig_handle.get_hatch())
legend_handle.set_linewidth(get_first(orig_handle.get_linewidths()))
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def update_from(self, other):
self._facecolor = other._facecolor
self._fill = other._fill
self._hatch = other._hatch
self._hatch_color = other._hatch_color
# copy the unscaled dash pattern
self._us_dashes = other._us_dashes
self.set_linewidth(other._linewidth) # also sets dash properties
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 963faed

Please sign in to comment.