8000 adding keyword plotting · matplotlib/matplotlib@596ceec · GitHub
[go: up one dir, main page]

Skip to content

Commit 596ceec

Browse files
committed
adding keyword plotting
1 parent dc9c93d commit 596ceec

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

doc/_static/mpl.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ body {
1919
}
2020

2121
a {
22-
color: #CA7900;
22+
color: #CA7900 !important;
2323
text-decoration: none;
2424
}
2525

examples/misc/keyword_plotting.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
======================
3+
Plotting with keywords
4+
======================
5+
6+
There are some instances where you have data in a format that lets you
7+
access particular variables with strings. For example, with
8+
:class:`numpy.recarray` or :class:`pandas.DataFrame`.
9+
10+
Matplotlib allows you provide such an object with
11+
the ``data`` keyword argument. If provided, then you may generate plots with
12+
the strings corresponding to these variables.
13+
"""
14+
15+
import numpy as np
16+
import matplotlib.pyplot as plt
17+
np.random.seed(19680801)
18+
19+
data = dict([('a', np.arange(50)),
20+
('c', np.random.randint(0, 50, 50)),
21+
('d', np.random.randn(50))])
22+
data['b'] = data['a'] + 10 * np.random.randn(50)
23+
data['d'] = np.abs(data['d']) * 100
24+
25+
fig, ax = plt.subplots()
26+
ax.scatter('a', 'b', c='c', s='d', data=data)
27+
ax.set(xlabel='a', ylabel='b')
28+
plt.show()

tutorials/01_introductory/pyplot.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,31 @@
9393
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
9494
plt.show()
9595

96+
###############################################################################
97+
# .. _plotting-with-keywords:
98+
#
99+
# Plotting with keyword strings
100+
# =============================
101+
#
102+
# There are some instances where you have data in a format that lets you
103+
# access particular variables with strings. For example, with
104+
# :class:`numpy.recarray` or :class:`pandas.DataFrame`.
105+
#
106+
# Matplotlib allows you provide such an object with
107+
# the ``data`` keyword argument. If provided, then you may generate plots with
108+
# the strings corresponding to these variables.
109+
110+
data = dict([('a', np.arange(50)),
111+
('c', np.random.randint(0, 50, 50)),
112+
('d', np.random.randn(50))])
113+
data['b'] = data['a'] + 10 * np.random.randn(50)
114+
data['d'] = np.abs(data['d']) * 100
115+
116+
plt.plot('a', 'b', color='c', data=data)
117+
plt.xlabel('a')
118+
plt.ylabel('b')
119+
plt.show()
120+
96121
###############################################################################
97122
# .. _controlling-line-properties:
98123
#

0 commit comments

Comments
 (0)
0