Figure and axes methods in matplotlib

Amelio Vazquez-Reina

Say I have the following setup:

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(5)
y = np.exp(x)
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.plot(x, y)

I would like to add a title to the plot (or to the subplot).

I tried:

> fig1.title('foo')
AttributeError: 'Figure' object has no attribute 'title'

and

> ax1.title('foo')
 TypeError: 'Text' object is not callable

How can I use the object-oriented programming interface to matplotlib to set these attributes?

More generally, where can I find the hierarchy of classes in matplotlib and their corresponding methods?

zhangxaochen

use ax1.set_title('foo') instead

ax1.title returns a matplotlib.text.Textobject:

In [289]: ax1.set_title('foo')
Out[289]: <matplotlib.text.Text at 0x939cdb0>

In [290]: print ax1.title
Text(0.5,1,'foo')

You can also add a centered title to the figure when there are multiple AxesSubplot:

In [152]: fig, ax=plt.subplots(1, 2)
     ...: fig.suptitle('title of subplots')
Out[152]: <matplotlib.text.Text at 0x94cf650>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

matplotlib add rectangle to Figure not to Axes

From Dev

Matplotlib's Figure and Axes explanation

From Dev

plotting methods to numerous possible axes on the same figure

From Dev

get axes ticks in matplotlib before drawing the figure

From Dev

Plot subplot axes in separate figure in matplotlib

From Java

What is the difference between drawing plots using plot, axes or figure in matplotlib?

From Dev

matplotlib get all axes that a given figure contains to apply some settings

From Dev

matplotlib pyplot 2 plots with different axes in same figure

From Dev

Modifying Matplotlib figure axes within PyQT4

From Dev

How to get the limits of plotted data from a Figure or Axes object in Matplotlib?

From Dev

matplotlib get all axes that a given figure contains to apply some settings

From Dev

Matplotlib imshow figure(2,2) image sizes proportional to axes

From Dev

Python figure and axes object

From Dev

How should I pass a matplotlib object through a function; as Axis, Axes or Figure?

From Java

How do I set the figure title and axes labels font size in Matplotlib?

From Dev

How should I pass a matplotlib object through a function; as Axis, Axes or Figure?

From Dev

Axes instance argument was not found in a figure

From Dev

Missing axes in figure with multiple subplots

From Dev

How to show specific axes in a figure

From Dev

Embed matplotlib figure in larger figure

From Dev

Matplotlib pyplot axes formatter

From Dev

On matplotlib logarithmic axes labels

From Dev

Set axes label in coordinate system of figure rather than axes

From Dev

use a matplotlib Figure in PyQt

From Dev

Save Matplotlib figure as TIFF

From Dev

matplotlib figure in GTK with tools

From Dev

Adjusting figure quality in matplotlib

From Dev

markers on loglog matplotlib figure

From Dev

Issue saving a matplotlib figure

Related Related

  1. 1

    matplotlib add rectangle to Figure not to Axes

  2. 2

    Matplotlib's Figure and Axes explanation

  3. 3

    plotting methods to numerous possible axes on the same figure

  4. 4

    get axes ticks in matplotlib before drawing the figure

  5. 5

    Plot subplot axes in separate figure in matplotlib

  6. 6

    What is the difference between drawing plots using plot, axes or figure in matplotlib?

  7. 7

    matplotlib get all axes that a given figure contains to apply some settings

  8. 8

    matplotlib pyplot 2 plots with different axes in same figure

  9. 9

    Modifying Matplotlib figure axes within PyQT4

  10. 10

    How to get the limits of plotted data from a Figure or Axes object in Matplotlib?

  11. 11

    matplotlib get all axes that a given figure contains to apply some settings

  12. 12

    Matplotlib imshow figure(2,2) image sizes proportional to axes

  13. 13

    Python figure and axes object

  14. 14

    How should I pass a matplotlib object through a function; as Axis, Axes or Figure?

  15. 15

    How do I set the figure title and axes labels font size in Matplotlib?

  16. 16

    How should I pass a matplotlib object through a function; as Axis, Axes or Figure?

  17. 17

    Axes instance argument was not found in a figure

  18. 18

    Missing axes in figure with multiple subplots

  19. 19

    How to show specific axes in a figure

  20. 20

    Embed matplotlib figure in larger figure

  21. 21

    Matplotlib pyplot axes formatter

  22. 22

    On matplotlib logarithmic axes labels

  23. 23

    Set axes label in coordinate system of figure rather than axes

  24. 24

    use a matplotlib Figure in PyQt

  25. 25

    Save Matplotlib figure as TIFF

  26. 26

    matplotlib figure in GTK with tools

  27. 27

    Adjusting figure quality in matplotlib

  28. 28

    markers on loglog matplotlib figure

  29. 29

    Issue saving a matplotlib figure

HotTag

Archive