-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
linking front thumbnails, updating screenshots + pyplot API page #8581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
0a58484
edf2cf8
aa88fae
a46410e
166a431
7e5bee9
cf76980
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,41 @@ | ||
Plotting commands summary | ||
========================= | ||
Below we describe several common approaches to plotting with Matplotlib. | ||
|
||
.. contents:: | ||
|
||
The Pyplot API | ||
-------------- | ||
|
||
The :mod:`matplotlib.pyplot` module contains functions that allow you to generate | ||
many kinds of plots quickly. For examples that showcase the use | ||
of the :mod:`matplotlib.pyplot` module, see the | ||
:ref:`sphx_glr_tutorials_01_introductory_pyplot.py` | ||
or the :ref:`pyplots_examples`. We also recommend that you look into | ||
the object-oriented approach to plotting, described below. | ||
|
||
.. currentmodule:: matplotlib.pyplot | ||
|
||
.. autofunction:: plotting | ||
|
||
The Object-Oriented API | ||
----------------------- | ||
|
||
Most of these functions also exist as methods in the | ||
:class:`matplotlib.axes.Axes` class. You can use them with the | ||
so-called "Object Oriented" approach to Matplotlib. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need so-called (it's redundant) |
||
|
||
While it is easy to quickly generate plots with the | ||
:mod:`matplotlib.pyplot` module, | ||
we recommend using the object-oriented approach for more control | ||
and customization of your plots. For some examples of the OO approach | ||
to Matplotlib, see the :ref:`api_examples` examples. | ||
|
||
Colors in Matplotlib | ||
-------------------- | ||
|
||
There are many colormaps you can use to map data onto color values. | ||
Below we list several ways in which color can be utilized in Matplotlib. | ||
|
||
For a more in-depth look at colormaps, see the | ||
:ref:`sphx_glr_tutorials_colors_colormaps.py` tutorial. | ||
|
||
.. autofunction:: colormaps |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
""" | ||
============================== | ||
Plotting categorical variables | ||
============================== | ||
|
||
How to use categorical variables in matplotlib. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Matplotlib |
||
|
||
Many times you want to create a plot that uses categorical variables | ||
in Matplotlib. For example, your data may naturally fall into | ||
several "bins" and you're interested in summarizing the data per | ||
bin. Matplotlib allows you to pass categorical variables directly to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think you need this sentence since this is a histogram:
|
||
many plotting functions. | ||
""" | ||
import matplotlib.pyplot as plt | ||
|
||
data = {'apples': 10, 'oranges': 15, 'lemons': 5, 'limes': 20} | ||
names = list(data.keys()) | ||
values = list(data.values()) | ||
|
||
fig, axs = plt.subplots(1, 3, figsize=(9, 3), sharey=True) | ||
axs[0].bar(names, values) | ||
axs[1].scatter(names, values) | ||
axs[2].plot(names, values) | ||
fig.suptitle('Categorical Plotting') | ||
|
||
|
||
############################################################################### | ||
# This works on both axes: | ||
|
||
cat = ["bored", "happy", "bored", "bored", "happy", "bored"] | ||
dog = ["happy", "happy", "happy", "happy", "bored", "bored"] | ||
activity = ["combing", "drinking", "feeding", "napping", "playing", "washing"] | ||
|
||
fig, ax = plt.subplots() | ||
ax.plot(activity, dog, label="dog") | ||
ax.plot(activity, cat, label="cat") | ||
ax.legend() | ||
|
||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,30 @@ | |
plt.ylabel('entry b') | ||
plt.show() | ||
|
||
############################################################################### | ||
# .. _plotting-with-categorical-vars: | ||
# | ||
# Plotting with categorical variables | ||
# =================================== | ||
# | ||
# It is also possible to create a plot using categorical variables | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing period. |
||
# Matplotlib allows you to pass categorical variables directly to | ||
# many plotting functions. For example: | ||
|
||
names = ['group_a', 'group_b', 'group_c'] | ||
values = [1, 10, 100] | ||
|
||
plt.figure(1, figsize=(9, 3)) | ||
|
||
plt.subplot(131) | ||
plt.bar(names, values) | ||
plt.subplot(132) | ||
plt.scatter(names, values) | ||
plt.subplot(133) | ||
plt.plot(names, values) | ||
plt.suptitle('Categorical Plotting') | ||
plt.show() | ||
|
||
############################################################################### | ||
# .. _controlling-line-properties: | ||
# | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we put this above the Pyplot API section? It could be formatted as an aside/callout/warning if needed. But I think
autofunction
generates a big table of functions (your site appears to be rendering a different PR, so I'm not sure), so no-one will ever see this recommendation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack yeah I'm sorry - I've got a buncha PRs open so it's hard to remember which one I've pushed to the website. I imagined just adding the section on OO stuff to the pyplot summary. It felt weird to put it at the beginning because the page is called
pyplot
. What if we instead called the pageplotting API
instead ofpyplot
? Then I could add the OO stuff first.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should note - this is w 8000 hy I put the
.. contents::
bit at the top of the page - it'll render a table of contents that will list all the sections. I hoped that would make it easier to find the OO section (and the colormaps section...though TBH I'm still not really sure why that section is on this page ¯\(ツ)/¯ )There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pushed this PR to the live version: http://predictablynoisy.com/matplotlib/api/pyplot_summary.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably think about this a bit in a later PR.