8000 Merge pull request #8566 from choldgraf/adding_data_kwarg · matplotlib/matplotlib@e232afe · GitHub
[go: up one dir, main page]

Skip to content

Commit e232afe

Browse files
authored
Merge pull request #8566 from choldgraf/adding_data_kwarg
adding keyword plotting
2 parents f84d715 + b7e31f3 commit e232afe

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
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

doc/conf.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
extensions = ['matplotlib.sphinxext.mathmpl', 'sphinxext.math_symbol_table',
3030
'sphinx.ext.autodoc', 'matplotlib.sphinxext.only_directives',
3131
'sphinx.ext.doctest', 'sphinx.ext.autosummary',
32-
'sphinx.ext.inheritance_diagram',
32+
'sphinx.ext.inheritance_diagram', 'sphinx.ext.intersphinx',
3333
'sphinx_gallery.gen_gallery',
3434
'matplotlib.sphinxext.plot_directive',
3535
'sphinxext.github',
@@ -88,6 +88,13 @@ def _check_deps():
8888

8989
autodoc_docstring_signature = True
9090

91+
intersphinx_mapping = {
92+
'python': ('https://docs.python.org/', None),
93+
'numpy': ('https://docs.scipy.org/doc/numpy/', None),
94+
'scipy': ('https://docs.scipy.org/doc/scipy/reference/', None),
95+
'pandas': ('http://pandas.pydata.org/pandas-docs/stable', None)
96+
}
97+
9198

9299
# Sphinx gallery configuration
93100
sphinx_gallery_conf = {

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 the ``data`` keyword
11+
argument. If provided, then you may generate plots with the strings
12+
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 = {'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='entry a', ylabel='entry 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 = {'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.scatter('a', 'b', c='c', s='d', data=data)
117+
plt.xlabel('entry a')
118+
plt.ylabel('entry b')
119+
plt.show()
120+
96121
###############################################################################
97122
# .. _controlling-line-properties:
98123
#

0 commit comments

Comments
 (0)
0