简体   繁体   中英

matplotlib how is a figure structured?

So I'm trying to understand how a figure is structured. My understanding is the following:

you have a canvas (if you've got a gui or something similar), a figure, and axes

you add the axes to the figure, and the figure to the canvas.

The plot is held by the axes, so for example:

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([1, 2], [1, 4])
fig.show()

I would expect would create a figure however I just get a blank window... Also, it seems canvas is not needed at all?

any help appreciated thank you!

here it says the above code should work... or has a similar example

https://github.com/thehackerwithin/PyTrieste/wiki/Python7-MatPlotLib

You shouldn't be poking at the canvas unless you really know what you are doing (and are embedding mpl into another program). pyplot has a bunch of nice tools that takes care of most of the set up for you.

There is a separation between the user layer (figures, axes, artists, and such) and the rendering layer (canvas, renderer, and such). The first layer is user facing and should be machine independent. The second layer is machine specific, but should expose none of that to the user.

There are a varity of 'backends' that take care of the translation between the two layers (by providing sub-classes of canvas and such). There are interactive backends (QtAgg, GtkAgg, TkAgg,...) which include all the hooks into a gui toolkit to provide nice windows and non-interactive backend (PS, pdf, ...) that only save files.

figure s hold axes which hold artists (and axis ). Those classes will talk to the rendering layer, but you (for the most part) do not need to worry about exactly how.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM