Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Huge off-screen filled polygons cause agg rasterizer to fail #3909

Closed as not planned
@Vayu

Description

@Vayu

Polygons are always fully rasterized before being clipped to viewport size. It causes rasterizer to fail in presence of huge polygons which extend outside current plotting limits.

matplotlib.pyplot.fill_between is a command that can produce such polygons inadvertently (zooming a plot with fill_between can also produce this error).

A simple example

import numpy as np
import matplotlib.pyplot as plt
plt.switch_backend('qt4agg')
yup = np.array([6e6, -0.1, 0.8])
ydown = np.array([2e6, -1.8, 0.5])
x = np.linspace(0, 2, 3)
axs = plt.subplot(111)
axs.fill_between(x, ydown, yup)
axs.set_xlim(1, 2)  # comment this to see full plot
axs.set_ylim(-2, 3)  # comment this to see full plot
plt.show()

Crashes (trace from 1.4.2 but problem is present in master as well)

Traceback (most recent call last):
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 338, in resizeEvent
    self.draw()
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_qt5agg.py", line 148, in draw
    FigureCanvasAgg.draw(self)
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 469, in draw
    self.figure.draw(self.renderer)
  File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/matplotlib/figure.py", line 1079, in draw
    func(*args)
  File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/matplotlib/axes/_base.py", line 2092, in draw
    a.draw(renderer)
  File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/matplotlib/collections.py", line 751, in draw
    Collection.draw(self, renderer)
  File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/matplotlib/collections.py", line 293, in draw
    mpath.Path(offsets), transOffset, tuple(facecolors[0]))
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 124, in draw_markers
    return self._renderer.draw_markers(*kl, **kw)
OverflowError: Allocated too many blocks

While the desired result would be
figure_1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions