Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Feature request - make it simpler to use full OO interface #1094

Closed
@astrofrog

Description

@astrofrog

I would like to start using the matplotlib OO interface more, as I would prefer to use this when interactive plotting is not needed. It it slightly faster, and behaves more intuitively in terms of reference counting (pyplot keeps a reference to each figure, meaning that if figures are not closed by pyplot, memory goes out of control).

The reason I don't use it is because it's not easy to remember all the set-up of the canvas and figure:

from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvasfrom matplotlib.figure import Figurefig = Figure()canvas = FigureCanvas(fig)ax = fig.add_subplot(1, 1, 1)ax.scatter(np.random.random(10), np.random.random(10))fig.savefig('test.png')

So I was wondering whether it would be possible to makeFigure more intelligent in terms of canvas? The 'ideal' API in my mind would be:

from matplotlib.figure import Figurefig = Figure()ax = fig.add_subplot(1, 1, 1)ax.scatter(np.random.random(10), np.random.random(10))fig.savefig('test.png')

i.e. I want the figure to just use the default backend (since this is set at the root level of matplotlib,not pyplot). So I would expect the following to work:

import matplotlibmatplotlib.use('Agg')from matplotlib.figure import Figurefig = Figure()ax = fig.add_subplot(1, 1, 1)ax.scatter(np.random.random(10), np.random.random(10))fig.savefig('test.png')

and to use the non-interactive Agg backend.

Is this something that has been considered before?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp