8000 Before rebase · matplotlib/matplotlib@782bbb1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 782bbb1

Browse files
committed
Before rebase
1 parent 8dac450 commit 782bbb1

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

tutorials/introductory/usage.py

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,29 @@
100100
# input. Classes that are similar to arrays ('array-like') such as `pandas`
101101
# data objects and `numpy.matrix` may not work as intended. Common convention
102102
# is to convert these to `numpy.array` objects prior to plotting.
103-
#
104-
# For example, to convert a `pandas.DataFrame` ::
105-
#
106-
# a = pandas.DataFrame(np.random.rand(4, 5), columns = list('abcde'))
107-
# a_asarray = a.values
108-
#
109-
# and to convert a `numpy.matrix` ::
103+
# For example, to convert a `numpy.matrix` ::
110104
#
111105
# b = np.matrix([[1, 2], [3, 4]])
112106
# b_asarray = np.asarray(b)
113107
#
108+
# There are some instances where you have data in a format that lets you
109+
# access particular variables with strings. For example, a *dict*, a
110+
# `numpy.recarray`, or a `pandas.DataFrame`. Matplotlib allows you provide
111+
# the ``data`` keyword argument and generate plots passing the strings
112+
# corresponding to these *x* and *y* variables.
113+
114+
data = {'a': np.arange(50),
115+
'c': np.random.randint(0, 50, 50),
116+
'd': np.random.randn(50)}
117+
data['b'] = data['a'] + 10 * np.random.randn(50)
118+
data['d'] = np.abs(data['d']) * 100
119+
120+
fig, ax = plt.subplots()
121+
ax.scatter('a', 'b', c='c', s='d', data=data)
122+
ax.set_xlabel('entry a')
123+
ax.set_ylabel('entry b')
124+
125+
##############################################################################
114126
# .. _coding_styles:
115127
#
116128
# The object-oriented interface and the pyplot interface
@@ -229,6 +241,28 @@ def my_plotter(ax, data1, data2, param_dict):
229241
# Matplotlib has one at `mpl-cookiecutter
230242
# <https://github.com/matplotlib/matplotlib-extension-cookiecutter>`_
231243
#
244+
# Working with multiple figures and axes
245+
# ======================================
246+
#
247+
# You can open multiple figures with multiple calls to
248+
# ``fig = plt.figure()`` or ``fig2, ax = plt.subplots()``. By keeping the
249+
# object references you can add artists to either figure.
250+
#
251+
# Multiple axes can be added a number of ways, but the most basic is
252+
# ``plt.subplots()`` as used above. One can achieve more complex layouts,
253+
# with axes spanning columns or rows, using `~.pyplot.subplot_mosaic`:
254+
255+
fig, axd = plt.subplot_mosaic([['upleft', 'right'],
256+
['lowleft', 'right']], constrained_layout=True)
257+
axd['upleft'].set_title('upleft')
258+
axd['lowleft'].set_title('lowleft')
259+
axd['right'].set_title('right')
260+
261+
262+
263+
264+
#
265+
#
232266
# More reading
233267
# ============
234268
#

0 commit comments

Comments
 (0)
0