Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Doc more backports #11524

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 4 commits into from
Jun 29, 2018
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: 14 additions & 0 deletions examples/color/color_by_yvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@
fig, ax = plt.subplots()
ax.plot(t, smiddle, t, slower, t, supper)
plt.show()

#############################################################################
#
# ------------
#
# References
# """"""""""
#
# The use of the following functions, methods, classes and modules is shown
# in this example:

import matplotlib
matplotlib.axes.Axes.plot
matplotlib.pyplot.plot
21 changes: 20 additions & 1 deletion examples/color/color_cycle_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Colors in the default property cycle
====================================

Display the colors from the default prop_cycle.
Display the colors from the default prop_cycle, which is obtained from the
:ref:`rc parameters<sphx_glr_tutorials_introductory_customizing.py>`.
"""
import numpy as np
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -38,3 +39,21 @@
fig.suptitle('Colors in the default prop_cycle', fontsize='large')

plt.show()

#############################################################################
#
# ------------
#
# References
# """"""""""
#
# The use of the following functions, methods, classes and modules is shown
# in this example:

import matplotlib
matplotlib.axes.Axes.axhline
matplotlib.axes.Axes.axvline
matplotlib.pyplot.axhline
matplotlib.pyplot.axvline
matplotlib.axes.Axes.set_facecolor
matplotlib.figure.Figure.suptitle
20 changes: 18 additions & 2 deletions examples/color/color_cycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

This example demonstrates two different APIs:

1. Setting the default rc parameter specifying the property cycle.
This affects all subsequent axes (but not axes already created).
1. Setting the default
:ref:`rc parameter<sphx_glr_tutorials_introductory_customizing.py>`
specifying the property cycle. This affects all subsequent axes
(but not axes already created).
2. Setting the property cycle for a single pair of axes.
"""
from cycler import cycler
Expand Down Expand Up @@ -39,3 +41,17 @@
# Tweak spacing between subplots to prevent labels from overlapping
fig.subplots_adjust(hspace=0.3)
plt.show()

#############################################################################
#
# ------------
#
# References
# """"""""""
#
# The use of the following functions, methods, classes and modules is shown
# in this example:

import matplotlib
matplotlib.axes.Axes.plot
matplotlib.axes.Axes.set_prop_cycle
79 changes: 61 additions & 18 deletions examples/color/color_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,75 @@
Color Demo
==========

matplotlib gives you 5 ways to specify colors,
Matplotlib gives you 8 ways to specify colors,

1) as a single letter string, ala MATLAB
1) an RGB or RGBA tuple of float values in ``[0, 1]`` (e.g. ``(0.1, 0.2, 0.5)``
or ``(0.1, 0.2, 0.5, 0.3)``). RGBA is short for Red, Green, Blue, Alpha;
2) a hex RGB or RGBA string (e.g., ``'#0F0F0F'`` or ``'#0F0F0F0F'``);
3) a string representation of a float value in ``[0, 1]`` inclusive for gray
level (e.g., ``'0.5'``);
4) a single letter string, i.e. one of
``{'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}``;
5) a X11/CSS4 ("html") color name, e.g. ``"blue"``;
6) a name from the `xkcd color survey <https://xkcd.com/color/rgb/>`__,
prefixed with ``'xkcd:'`` (e.g., ``'xkcd:sky blue'``);
7) a "Cn" color spec, i.e. `'C'` followed by a single digit, which is an index
into the default property cycle
(``matplotlib.rcParams['axes.prop_cycle']``); the indexing occurs at artist
creation time and defaults to black if the cycle does not include color.
8) one of ``{'tab:blue', 'tab:orange', 'tab:green',
'tab:red', 'tab:purple', 'tab:brown', 'tab:pink',
'tab:gray', 'tab:olive', 'tab:cyan'}`` which are the Tableau Colors from the
'tab10' categorical palette (which is the default color cycle);

2) as an html style hex string or html color name
For more information on colors in matplotlib see

3) as an R,G,B tuple, where R,G,B, range from 0-1

4) as a string representing a floating point number
from 0 to 1, corresponding to shades of gray.

5) as a special color "Cn", where n is a number 0-9 specifying the
nth color in the currently active color cycle.

See help(colors) for more info.
* the :ref:`sphx_glr_tutorials_colors_colors.py` tutorial;
* the `matplotlib.colors` API;
* the :ref:`sphx_glr_gallery_color_named_colors.py` example.
"""

import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0.0, 2.0, 0.01)
t = np.linspace(0.0, 2.0, 201)
s = np.sin(2 * np.pi * t)

fig, ax = plt.subplots(facecolor='darkslategray')
ax.plot(t, s, 'C1')
ax.set_xlabel('time (s)', color='C1')
ax.set_ylabel('voltage (mV)', color='0.5') # grayscale color
ax.set_title('About as silly as it gets, folks', color='#afeeee')
# 1) RGB tuple:
fig, ax = plt.subplots(facecolor=(.18, .31, .31))
# 2) hex string:
ax.set_facecolor('#eafff5')
# 3) gray level string:
ax.set_title('Voltage vs. time chart', color='0.7')
# 4) single letter color string
ax.set_xlabel('time (s)', color='c')
# 5) a named color:
ax.set_ylabel('voltage (mV)', color='peachpuff')
# 6) a named xkcd color:
ax.plot(t, s, 'xkcd:crimson')
# 7) Cn notation:
ax.plot(t, .7*s, color='C4', linestyle='--')
# 8) tab notation:
ax.tick_params(labelcolor='tab:orange')


plt.show()

#############################################################################
#
# ------------
#
# References
# """"""""""
#
# The use of the following functions, methods, classes and modules is shown
# in this example:

import matplotlib
matplotlib.colors
matplotlib.axes.Axes.plot
matplotlib.axes.Axes.set_facecolor
matplotlib.axes.Axes.set_title
matplotlib.axes.Axes.set_xlabel
matplotlib.axes.Axes.set_ylabel
matplotlib.axes.Axes.tick_params
21 changes: 19 additions & 2 deletions examples/color/colorbar_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
Colorbar
========

Use colorbar by specifying the mappable object (here
the imshow returned object) and the axes to attach the colorbar to.
Use `~.figure.Figure.colorbar` by specifying the mappable object (here
the `~.matplotlib.image.AxesImage` returned by `~.axes.Axes.imshow`)
and the axes to attach the colorbar to.
"""

import numpy as np
Expand Down Expand Up @@ -35,3 +36,19 @@
fig.colorbar(neg, ax=ax2)

plt.show()

#############################################################################
#
# ------------
#
# References
# """"""""""
#
# The use of the following functions, methods, classes and modules is shown
# in this example:

import matplotlib
matplotlib.axes.Axes.imshow
matplotlib.pyplot.imshow
matplotlib.figure.Figure.colorbar
matplotlib.pyplot.colorbar
16 changes: 16 additions & 0 deletions examples/color/colormap_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,19 @@ def plot_color_gradients(cmap_category, cmap_list, nrows):
plot_color_gradients(cmap_category, cmap_list, nrows)

plt.show()

#############################################################################
#
# ------------
#
# References
# """"""""""
#
# The use of the following functions, methods, classes and modules is shown
# in this example:

import matplotlib
matplotlib.colors
matplotlib.axes.Axes.imshow
matplotlib.figure.Figure.text
matplotlib.axes.Axes.set_axis_off
25 changes: 25 additions & 0 deletions examples/color/named_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
========================

Simple plot example with the named colors and its visual representation.

For more information on colors in matplotlib see

* the :ref:`sphx_glr_tutorials_colors_colors.py` tutorial;
* the `matplotlib.colors` API;
* the :ref:`sphx_glr_gallery_color_color_demo.py`.
"""
from __future__ import division

Expand Down Expand Up @@ -53,3 +59,22 @@
top=1, bottom=0,
hspace=0, wspace=0)
plt.show()

#############################################################################
#
# ------------
#
# References
# """"""""""
#
# The use of the following functions, methods, classes and modules is shown
# in this example:

import matplotlib
matplotlib.colors
matplotlib.colors.rgb_to_hsv
matplotlib.colors.to_rgba
matplotlib.figure.Figure.get_size_inches
matplotlib.figure.Figure.subplots_adjust
matplotlib.axes.Axes.text
matplotlib.axes.Axes.hlines
23 changes: 23 additions & 0 deletions examples/images_contours_and_fields/affine_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
Affine transform of an image
============================


Prepending an affine transformation (:class:`~.transforms.Affine2D`)
to the :ref:`data transform <data-coords>`
of an image allows to manipulate the image's shape and orientation.
This is an example of the concept of
:ref:`transform chaining <transformation-pipeline>`.

For the backends that support draw_image with optional affine
transform (e.g., agg, ps backend), the image of the output should
have its boundary match the dashed yellow rectangle.
Expand Down Expand Up @@ -57,3 +64,19 @@ def do_plot(ax, Z, transform):
rotate_deg(30).skew_deg(30, 15).scale(-1, .5).translate(.5, -1))

plt.show()


#############################################################################
#
# ------------
#
# References
# """"""""""
#
# The use of the following functions, methods and classes is shown
# in this example:

import matplotlib
matplotlib.axes.Axes.imshow
matplotlib.pyplot.imshow
matplotlib.transforms.Affine2D
38 changes: 24 additions & 14 deletions examples/images_contours_and_fields/barb_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,23 @@
data = np.array(data, dtype=[('x', np.float32), ('y', np.float32),
('u', np.float32), ('v', np.float32)])

fig1, axs1 = plt.subplots(nrows=2, ncols=2)
# Default parameters, uniform grid
ax = plt.subplot(2, 2, 1)
ax.barbs(X, Y, U, V)
axs1[0, 0].barbs(X, Y, U, V)

# Arbitrary set of vectors, make them longer and change the pivot point
# (point around which they're rotated) to be the middle
ax = plt.subplot(2, 2, 2)
ax.barbs(data['x'], data['y'], data['u'], data['v'], length=8, pivot='middle')
axs1[0, 1].barbs(data['x'], data['y'], data['u'], data['v'], length=8, pivot='middle')

# Showing colormapping with uniform grid. Fill the circle for an empty barb,
# don't round the values, and change some of the size parameters
ax = plt.subplot(2, 2, 3)
ax.barbs(X, Y, U, V, np.sqrt(U * U + V * V), fill_empty=True, rounding=False,
sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3))
axs1[1, 0].barbs(X, Y, U, V, np.sqrt(U * U + V * V), fill_empty=True, rounding=False,
sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3))

# Change colors as well as the increments for parts of the barbs
ax = plt.subplot(2, 2, 4)
ax.barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r',
barbcolor=['b', 'g'],
barb_increments=dict(half=10, full=20, flag=100), flip_barb=True)
axs1[1, 1].barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r',
barbcolor=['b', 'g'], flip_barb=True,
barb_increments=dict(half=10, full=20, flag=100))

# Masked arrays are also supported
masked_u = np.ma.masked_array(data['u'])
Expand All @@ -50,8 +47,21 @@

# Identical plot to panel 2 in the first figure, but with the point at
# (0.5, 0.25) missing (masked)
fig2 = plt.figure()
ax = fig2.add_subplot(1, 1, 1)
ax.barbs(data['x'], data['y'], masked_u, data['v'], length=8, pivot='middle')
fig2, ax2 = plt.subplots()
ax2.barbs(data['x'], data['y'], masked_u, data['v'], length=8, pivot='middle')

plt.show()

#############################################################################
#
# ------------
#
# References
# """"""""""
#
# The use of the following functions, methods and classes is shown
# in this example:

import matplotlib
matplotlib.axes.Axes.barbs
matplotlib.pyplot.barbs
25 changes: 20 additions & 5 deletions examples/images_contours_and_fields/barcode_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Barcode Demo
============

This demo shows how to produce a one-dimensional image, or "bar code".
"""
import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -19,13 +20,27 @@

fig = plt.figure()

# a vertical barcode -- this is broken at present
ax = fig.add_axes([0.1, 0.3, 0.1, 0.6], **axprops)
ax.imshow(x.reshape((-1, 1)), **barprops)
# a vertical barcode
ax1 = fig.add_axes([0.1, 0.3, 0.1, 0.6], **axprops)
ax1.imshow(x.reshape((-1, 1)), **barprops)

# a horizontal barcode
ax = fig.add_axes([0.3, 0.1, 0.6, 0.1], **axprops)
ax.imshow(x.reshape((1, -1)), **barprops)
ax2 = fig.add_axes([0.3, 0.1, 0.6, 0.1], **axprops)
ax2.imshow(x.reshape((1, -1)), **barprops)


plt.show()

#############################################################################
#
# ------------
#
# References
# """"""""""
#
# The use of the following functions, methods and classes is shown
# in this example:

import matplotlib
matplotlib.axes.Axes.imshow
matplotlib.pyplot.imshow
Loading