-
-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0a58484
linking front thumbnails and updating screenshots
choldgraf edf2cf8
adding pyplot API context
choldgraf aa88fae
categorical variable example
choldgraf a46410e
addressing comments
choldgraf 166a431
ableist language
choldgraf 7e5bee9
addressing comments
choldgraf cf76980
Update categorical_variables.py
choldgraf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,43 @@ | ||
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 | ||
"Object Oriented" approach to Matplotlib. | ||
|
||
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. See the methods in the | ||
:meth:`matplotlib.axes.Axes` class for many of the same plotting functions. | ||
For examples of the OO approach to Matplotlib, see the | ||
:ref:`API Examples<api_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 contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
============================== | ||
Plotting categorical variables | ||
============================== | ||
|
||
How to use categorical variables in Matplotlib. | ||
|
||
Many times you want to create a plot that uses categorical variables | ||
in Matplotlib. Matplotlib allows you to pass categorical variables directly to | ||
many plotting functions, which we demonstrate below. | ||
""" | ||
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 why 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.