8000 linking front thumbnails, updating screenshots + pyplot API page by choldgraf · Pull Request #8581 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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 7 commits into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions doc/_templates/index.html
10000
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ <h1>Introduction</h1>
interface toolkits.</p>

<div class="responsive_screenshots">
<a a href="{{ pathto('users/screenshots') }}">
<a a href="{{ pathto('tutorials/01_introductory/sample_plots') }}">
<div class="responsive_subfig">
<img align="middle", src="{{ pathto('_static/membrane_frontpage.png', 1) }}", border="0", alt="screenshots"/>
<img align="middle", src="{{ pathto('_images/sphx_glr_membrane_thumb.png', 1) }}", border="0", alt="screenshots"/>
</div>
<div class="responsive_subfig">
<img align="middle", src="{{ pathto('_static/histogram_frontpage.png', 1) }}", border="0", alt="screenshots"/>
<img align="middle", src="{{ pathto('_images/sphx_glr_histogram_thumb1.png', 1) }}", border="0", alt="screenshots"/>
</div>
<div class="responsive_subfig">
<img align="middle", src="{{ pathto('_static/contour_frontpage.png', 1) }}", border="0", alt="screenshots"/>
<img align="middle", src="{{ pathto('_images/sphx_glr_contour_thumb.png', 1) }}", border="0", alt="screenshots"/>
</div>
<div class="responsive_subfig">
<img align="middle", src="{{ pathto('_static/surface3d_frontpage.png', 1) }}", border="0", alt="screenshots"/>
<img align="middle", src="{{ pathto('_images/sphx_glr_3D_thumb.png', 1) }}", border="0", alt="screenshots"/>
</div>
</a>
</div>
Expand All @@ -75,8 +75,8 @@ <h1>Introduction</h1>
<p>Matplotlib tries to make easy things easy and hard things possible.
You can generate plots, histograms, power spectra, bar charts,
errorcharts, scatterplots, etc., with just a few lines of code.
For a example, see the <a href="{{ pathto('users/screenshots')
}}">screenshots</a> and <a href="{{ pathto('gallery/index') }}">thumbnail</a> gallery.</p>
For examples, see the <a href="{{ pathto('tutorials/01_introductory/sample_plots')
}}">sample plots</a> and <a href="{{ pathto('gallery/index') }}">thumbnail</a> gallery.</p>

<p>For simple plotting the <tt>pyplot</tt> module provides a
MATLAB-like interface, particularly when combined
Expand Down
39 changes: 37 additions & 2 deletions doc/api/pyplot_summary.rst
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
Copy link
Member
@QuLogic QuLogic May 11, 2017

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.

Copy link
Contributor Author

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 page plotting API instead of pyplot? Then I could add the OO stuff first.

Copy link
Contributor Author
@choldgraf choldgraf May 11, 2017

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 ¯\(ツ)/¯ )

Copy link
Contributor Author

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

Copy link
Member

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.

-----------------------

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
2 changes: 1 addition & 1 deletion doc/contents.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Overview
:maxdepth: 2

users/index.rst
api/index.rst
faq/index.rst
mpl_toolkits/index.rst
resources/index.rst
thirdpartypackages/index.rst
api/index.rst
devel/index.rst
glossary/index.rst

Expand Down
44 changes: 0 additions & 44 deletions doc/make.py
A3DB
Original file line number Diff line number Diff line change
Expand Up @@ -52,45 +52,6 @@ def linkcheck():
[sys.executable]
+ '-msphinx -b linkcheck -d build/doctrees . build/linkcheck'.split())


# For generating PNGs of the top row of index.html:
FRONTPAGE_PY_PATH = "../examples/frontpage/" # python scripts location
FRONTPAGE_PNG_PATH = "_static/" # png files location
# png files and corresponding generation scripts:
FRONTPAGE_PNGS = {"surface3d_frontpage.png": "3D.py",
"contour_frontpage.png": "contour.py",
"histogram_frontpage.png": "histogram.py",
"membrane_frontpage.png": "membrane.py"}


def generate_frontpage_pngs(only_if_needed=True):
"""Executes the scripts for PNG generation of the top row of index.html.

If `only_if_needed` is `True`, then the PNG file is only generated, if it
doesn't exist or if the python file is newer.

Note that the element `div.responsive_screenshots` in the file
`_static/mpl.css` has the height and cumulative width of the used PNG files
as attributes. This ensures that the magnification of those PNGs is <= 1.
"""
for fn_png, fn_py in FRONTPAGE_PNGS.items():
pn_png = os.path.join(FRONTPAGE_PNG_PATH, fn_png) # get full paths
pn_py = os.path.join(FRONTPAGE_PY_PATH, fn_py)

# Read file modification times:
mtime_py = os.path.getmtime(pn_py)
mtime_png = (os.path.getmtime(pn_png) if os.path.exists(pn_png) else
mtime_py - 1) # set older time, if file doesn't exist

if only_if_needed and mtime_py <= mtime_png:
continue # do nothing if png is newer

# Execute python as subprocess (preferred over os.system()):
subprocess.check_call(
[sys.executable, pn_py]) # raises CalledProcessError()
os.rename(fn_png, pn_png) # move file to _static/ directory


DEPSY_PATH = "_static/depsy_badge.svg"
DEPSY_URL = "http://depsy.org/api/package/pypi/matplotlib/badge.svg"
DEPSY_DEFAULT = "_static/depsy_badge_default.svg"
Expand Down Expand Up @@ -121,7 +82,6 @@ def fetch_depsy_badge():
def html(buildername='html'):
"""Build Sphinx 'html' target. """
check_build()
generate_frontpage_pngs()
fetch_depsy_badge()

rc = '../lib/matplotlib/mpl-data/matplotlibrc'
Expand Down Expand Up @@ -213,10 +173,6 @@ def clean():
for filename in glob.glob(pattern):
if os.path.exists(filename):
os.remove(filename)
for fn in FRONTPAGE_PNGS.keys(): # remove generated PNGs
pn = os.path.join(FRONTPAGE_PNG_PATH, fn)
if os.path.exists(pn):
os.remove(os.path.join(pn))


def build_all():
Expand Down
7 changes: 0 additions & 7 deletions doc/users/examples_index.rst

This file was deleted.

1 change: 0 additions & 1 deletion doc/users/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ User's Guide
intro.rst
installing.rst
interactive.rst
examples_index
whats_new.rst
github_stats.rst
license.rst
Expand Down
37 changes: 37 additions & 0 deletions examples/lines_bars_and_markers/categorical_variables.py
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()
24 changes: 24 additions & 0 deletions tutorials/01_introductory/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
# 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:
#
Expand Down
Loading
0