Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return values of subplot

Currently I trying to get myself acquainted with the matplotlib.pyplot library. After having seeing quite some examples and tutorial, I noticed that the subplots function also has some returns values which usually are used later on. However, on the matplotlib website I was unable to find any specification on what exactly is returned, and none of the examples are the same (although it usually seems to be an ax object). Can you guys give me some to pointers as to what is returned, and how I can use it. Thanks in advance!

like image 809
Dearis Avatar asked Apr 15 '15 07:04

Dearis


1 Answers

In the documentation it says that matplotlib.pyplot.subplots return an instance of Figure and an array of (or a single) Axes (array or not depends on the number of subplots).

Common use is:

import matplotlib.pyplot as plt
import numpy as np
f, axes = plt.subplots(1,2)  # 1 row containing 2 subplots.

# Plot random points on one subplots.
axes[0].scatter(np.random.randn(10), np.random.randn(10))

# Plot histogram on the other one.
axes[1].hist(np.random.randn(100))

# Adjust the size and layout through the Figure-object.
f.set_size_inches(10, 5)
f.tight_layout()
like image 163
RickardSjogren Avatar answered Oct 16 '22 02:10

RickardSjogren