Skip to content

DOC: Adding example references for Shapes,Pie&Polar,Color sections #11209

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
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 @@ -43,3 +45,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`.
"""

import matplotlib.pyplot as plt
Expand Down Expand Up @@ -52,3 +58,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
19 changes: 19 additions & 0 deletions examples/pie_and_polar_charts/nested_pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,22 @@
ax.set(title="Pie plot with `ax.bar` and polar coordinates")
ax.set_axis_off()
plt.show()

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

import matplotlib
matplotlib.axes.Axes.pie
matplotlib.pyplot.pie
matplotlib.axes.Axes.bar
matplotlib.pyplot.bar
matplotlib.projections.polar
matplotlib.axes.Axes.set
matplotlib.axes.Axes.set_axis_off
17 changes: 17 additions & 0 deletions examples/pie_and_polar_charts/pie_and_donut_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,20 @@ def func(pct, allvals):
# And here it is, the donut. Note however, that if we were to use this recipe,
# the ingredients would suffice for around 6 donuts - producing one huge
# donut is untested and might result in kitchen errors.


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

import matplotlib
matplotlib.axes.Axes.pie
matplotlib.pyplot.pie
matplotlib.axes.Axes.legend
matplotlib.pyplot.legend
16 changes: 15 additions & 1 deletion examples/pie_and_polar_charts/pie_demo2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Pie Demo2
=========

Make a pie charts using :meth:`.Axes.pie`.
Make a pie charts using :meth:`~.axes.Axes.pie`.

This example demonstrates some pie chart features like labels, varying size,
autolabeling the percentage, offsetting a slice and adding a shadow.
Expand Down Expand Up @@ -44,3 +44,17 @@
autotexts[0].set_color('white')

plt.show()

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

import matplotlib
matplotlib.axes.Axes.pie
matplotlib.pyplot.pie
14 changes: 14 additions & 0 deletions examples/pie_and_polar_charts/pie_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,17 @@
ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.

plt.show()

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

import matplotlib
matplotlib.axes.Axes.pie
matplotlib.pyplot.pie
15 changes: 15 additions & 0 deletions examples/pie_and_polar_charts/polar_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,18 @@
bar.set_alpha(0.5)

plt.show()

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

import matplotlib
matplotlib.axes.Axes.bar
matplotlib.pyplot.bar
matplotlib.projections.polar
18 changes: 18 additions & 0 deletions examples/pie_and_polar_charts/polar_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,21 @@

ax.set_title("A line plot on a polar axis", va='bottom')
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.projections.polar
matplotlib.projections.polar.PolarAxes
matplotlib.projections.polar.PolarAxes.set_rticks
matplotlib.projections.polar.PolarAxes.set_rmax
matplotlib.projections.polar.PolarAxes.set_rlabel_position
Loading