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

Skip to content

Commit cb9c28c

Browse files
committed
working on guide for choosing colormaps. Have overview section and start on a few others.
1 parent abdd1cc commit cb9c28c

1 file changed

Lines changed: 330 additions & 0 deletions

File tree

doc/users/colormaps.rst

Lines changed: 330 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,330 @@
1+
.. _colormaps:
2+
3+
******************
4+
Choosing Colormaps
5+
******************
6+
7+
8+
Overview
9+
========
10+
11+
The idea behind choosing a good colormap is to find a good representation in 3D colorspace for your data set. The best colormap for any given data set depends on many things including:
12+
13+
- Whether representing form or metric data (link to C. Ware paper and explain more)
14+
- Your knowledge of the data set (*i.e.*, is there a critical value from which the other values deviate?)
15+
- If there is an intuitive color scheme for the parameter you are plotting
16+
- If there is a standard in the field the audience may be expecting
17+
18+
For many applications, a perceptual colormap is the best choice |---| one in which equal steps in data are perceived as equal steps in the color space. Researchers have found that the human brain perceives changes in the lightness parameter as changes in the data much better than, for example, changes in hue. Therefore, colormaps which have monotonically increasing lightness through the colormap will be better interpreted by the viewer.
19+
20+
Color can be represented in 3D space in various ways. One way to represent color is using CIELAB (CITE). In CIELAB, color space is represented by lightness, :math:`L^*`; red-green, :math:`a`; and yellow-blue, :math:`b`. The lightness parameter :math:`L^*` can then be used to learn more about how the matplotlib colormaps will be perceived by viewers.
21+
22+
23+
Sequential and diverging colormaps
24+
==================================
25+
26+
STUFF
27+
28+
29+
Lightness of matplotlib colormaps
30+
=================================
31+
32+
.. plot:: users/plotting/colormaps/lightness.py
33+
34+
For the Sequential plots, the lightness value increases monotonically through the colormaps. This is good. Some of the :math:`L^*` values in the colormaps span from 0 to 100 (binary and the other grayscale), and others start around :math:`L^*=20`.
35+
36+
Some of the :math:`L^*` values from the Sequential2 plots are monotonically increasing, but some, such as cool and spring, plateau or even go both up and down in :math:`L^*` space. Data that is being represented in a region of the colormap that is at a plateau will lead to a perception of the data all having the same value (SHOW EXAMPLE?).
37+
38+
For the Diverging maps, we want to have monotonically increasing :math:`L^*` values up to a maximum, which should be close to :math:`L^*=100`, followed by monotonically decreasing :math:`L^*` values. We are looking for approximately equal minimum :math:`L^*` values at opposite ends of the colormap. Additionally, we might prefer a diverging colormap which has a rounded instead of pointed peak for retaining some spread of values around the critical point. By these measures, BrBG and RdBu are good options. coolwarm is a good option, but it doesn't span a wide range of :math:`L^*` values (see grayscale section).
39+
40+
41+
:math:`L^*` function
42+
====================
43+
44+
WHAT FUNCTION FOR :math:`L^*`?
45+
46+
47+
References
48+
==========
49+
50+
- C. Ware
51+
- M. Niccoli
52+
- IBM paper
53+
- More
54+
55+
.. :mod:`matplotlib.pyplot` is a collection of command style functions
56+
.. that make matplotlib work like MATLAB.
57+
.. Each ``pyplot`` function makes
58+
.. some change to a figure: eg, create a figure, create a plotting area
59+
.. in a figure, plot some lines in a plotting area, decorate the plot
60+
.. with labels, etc.... :mod:`matplotlib.pyplot` is stateful, in that it
61+
.. keeps track of the current figure and plotting area, and the plotting
62+
.. functions are directed to the current axes
63+
64+
.. .. plot:: pyplots/pyplot_simple.py
65+
.. :include-source:
66+
67+
.. You may be wondering why the x-axis ranges from 0-3 and the y-axis
68+
.. from 1-4. If you provide a single list or array to the
69+
.. :func:`~matplotlib.pyplot.plot` command, matplotlib assumes it is a
70+
.. sequence of y values, and automatically generates the x values for
71+
.. you. Since python ranges start with 0, the default x vector has the
72+
.. same length as y but starts with 0. Hence the x data are
73+
.. ``[0,1,2,3]``.
74+
75+
.. :func:`~matplotlib.pyplot.plot` is a versatile command, and will take
76+
.. an arbitrary number of arguments. For example, to plot x versus y,
77+
.. you can issue the command::
78+
79+
.. plt.plot([1,2,3,4], [1,4,9,16])
80+
81+
.. For every x, y pair of arguments, there is an optional third argument
82+
.. which is the format string that indicates the color and line type of
83+
.. the plot. The letters and symbols of the format string are from
84+
.. MATLAB, and you concatenate a color string with a line style string.
85+
.. The default format string is 'b-', which is a solid blue line. For
86+
.. example, to plot the above with red circles, you would issue
87+
88+
.. .. plot:: pyplots/pyplot_formatstr.py
89+
.. :include-source:
90+
91+
.. See the :func:`~matplotlib.pyplot.plot` documentation for a complete
92+
.. list of line styles and format strings. The
93+
.. :func:`~matplotlib.pyplot.axis` command in the example above takes a
94+
.. list of ``[xmin, xmax, ymin, ymax]`` and specifies the viewport of the
95+
.. axes.
96+
97+
.. If matplotlib were limited to working with lists, it would be fairly
98+
.. useless for numeric processing. Generally, you will use `numpy
99+
.. <http://numpy.scipy.org>`_ arrays. In fact, all sequences are
100+
.. converted to numpy arrays internally. The example below illustrates a
101+
.. plotting several lines with different format styles in one command
102+
.. using arrays.
103+
104+
.. .. plot:: pyplots/pyplot_three.py
105+
.. :include-source:
106+
107+
.. .. _controlling-line-properties:
108+
109+
.. Controlling line properties
110+
.. ===========================
111+
112+
.. Lines have many attributes that you can set: linewidth, dash style,
113+
.. antialiased, etc; see :class:`matplotlib.lines.Line2D`. There are
114+
.. several ways to set line properties
115+
116+
.. * Use keyword args::
117+
118+
.. plt.plot(x, y, linewidth=2.0)
119+
120+
121+
.. * Use the setter methods of the ``Line2D`` instance. ``plot`` returns a list
122+
.. of lines; eg ``line1, line2 = plot(x1,y1,x2,y2)``. Below I have only
123+
.. one line so it is a list of length 1. I use tuple unpacking in the
124+
.. ``line, = plot(x, y, 'o')`` to get the first element of the list::
125+
126+
.. line, = plt.plot(x, y, '-')
127+
.. line.set_antialiased(False) # turn off antialising
128+
129+
.. * Use the :func:`~matplotlib.pyplot.setp` command. The example below
130+
.. uses a MATLAB-style command to set multiple properties
131+
.. on a list of lines. ``setp`` works transparently with a list of objects
132+
.. or a single object. You can either use python keyword arguments or
133+
.. MATLAB-style string/value pairs::
134+
135+
.. lines = plt.plot(x1, y1, x2, y2)
136+
.. # use keyword args
137+
.. plt.setp(lines, color='r', linewidth=2.0)
138+
.. # or MATLAB style string value pairs
139+
.. plt.setp(lines, 'color', 'r', 'linewidth', 2.0)
140+
141+
142+
.. Here are the available :class:`~matplotlib.lines.Line2D` properties.
143+
144+
.. ====================== ==================================================
145+
.. Property Value Type
146+
.. ====================== ==================================================
147+
.. alpha float
148+
.. animated [True | False]
149+
.. antialiased or aa [True | False]
150+
.. clip_box a matplotlib.transform.Bbox instance
151+
.. clip_on [True | False]
152+
.. clip_path a Path instance and a Transform instance, a Patch
153+
.. color or c any matplotlib color
154+
.. contains the hit testing function
155+
.. dash_capstyle [``'butt'`` | ``'round'`` | ``'projecting'``]
156+
.. dash_joinstyle [``'miter'`` | ``'round'`` | ``'bevel'``]
157+
.. dashes sequence of on/off ink in points
158+
.. data (np.array xdata, np.array ydata)
159+
.. figure a matplotlib.figure.Figure instance
160+
.. label any string
161+
.. linestyle or ls [ ``'-'`` | ``'--'`` | ``'-.'`` | ``':'`` | ``'steps'`` | ...]
162+
.. linewidth or lw float value in points
163+
.. lod [True | False]
164+
.. marker [ ``'+'`` | ``','`` | ``'.'`` | ``'1'`` | ``'2'`` | ``'3'`` | ``'4'`` ]
165+
.. markeredgecolor or mec any matplotlib color
166+
.. markeredgewidth or mew float value in points
167+
.. markerfacecolor or mfc any matplotlib color
168+
.. markersize or ms float
169+
.. markevery [ None | integer | (startind, stride) ]
170+
.. picker used in interactive line selection
171+
.. pickradius the line pick selection radius
172+
.. solid_capstyle [``'butt'`` | ``'round'`` | ``'projecting'``]
173+
.. solid_joinstyle [``'miter'`` | ``'round'`` | ``'bevel'``]
174+
.. transform a matplotlib.transforms.Transform instance
175+
.. visible [True | False]
176+
.. xdata np.array
177+
.. ydata np.array
178+
.. zorder any number
179+
.. ====================== ==================================================
180+
181+
.. To get a list of settable line properties, call the
182+
.. :func:`~matplotlib.pyplot.setp` function with a line or lines
183+
.. as argument
184+
185+
.. .. sourcecode:: ipython
186+
187+
.. In [69]: lines = plt.plot([1,2,3])
188+
189+
.. In [70]: plt.setp(lines)
190+
.. alpha: float
191+
.. animated: [True | False]
192+
.. antialiased or aa: [True | False]
193+
.. ...snip
194+
195+
.. .. _multiple-figs-axes:
196+
197+
.. Working with multiple figures and axes
198+
.. ======================================
199+
200+
201+
.. MATLAB, and :mod:`~matplotlib.pyplot`, have the concept of the current
202+
.. figure and the current axes. All plotting commands apply to the
203+
.. current axes. The function :func:`~matplotlib.pyplot.gca` returns the
204+
.. current axes (a :class:`matplotlib.axes.Axes` instance), and
205+
.. :func:`~matplotlib.pyplot.gcf` returns the current figure
206+
.. (:class:`matplotlib.figure.Figure` instance). Normally, you don't have
207+
.. to worry about this, because it is all taken care of behind the
208+
.. scenes. Below is a script to create two subplots.
209+
210+
.. .. plot:: pyplots/pyplot_two_subplots.py
211+
.. :include-source:
212+
213+
.. The :func:`~matplotlib.pyplot.figure` command here is optional because
214+
.. ``figure(1)`` will be created by default, just as a ``subplot(111)``
215+
.. will be created by default if you don't manually specify an axes. The
216+
.. :func:`~matplotlib.pyplot.subplot` command specifies ``numrows,
217+
.. numcols, fignum`` where ``fignum`` ranges from 1 to
218+
.. ``numrows*numcols``. The commas in the ``subplot`` command are
219+
.. optional if ``numrows*numcols<10``. So ``subplot(211)`` is identical
220+
.. to ``subplot(2,1,1)``. You can create an arbitrary number of subplots
221+
.. and axes. If you want to place an axes manually, ie, not on a
222+
.. rectangular grid, use the :func:`~matplotlib.pyplot.axes` command,
223+
.. which allows you to specify the location as ``axes([left, bottom,
224+
.. width, height])`` where all values are in fractional (0 to 1)
225+
.. coordinates. See :ref:`pylab_examples-axes_demo` for an example of
226+
.. placing axes manually and :ref:`pylab_examples-subplots_demo` for an
227+
.. example with lots-o-subplots.
228+
229+
230+
.. You can create multiple figures by using multiple
231+
.. :func:`~matplotlib.pyplot.figure` calls with an increasing figure
232+
.. number. Of course, each figure can contain as many axes and subplots
233+
.. as your heart desires::
234+
235+
.. import matplotlib.pyplot as plt
236+
.. plt.figure(1) # the first figure
237+
.. plt.subplot(211) # the first subplot in the first figure
238+
.. plt.plot([1,2,3])
239+
.. plt.subplot(212) # the second subplot in the first figure
240+
.. plt.plot([4,5,6])
241+
242+
243+
.. plt.figure(2) # a second figure
244+
.. plt.plot([4,5,6]) # creates a subplot(111) by default
245+
246+
.. plt.figure(1) # figure 1 current; subplot(212) still current
247+
.. plt.subplot(211) # make subplot(211) in figure1 current
248+
.. plt.title('Easy as 1,2,3') # subplot 211 title
249+
250+
.. You can clear the current figure with :func:`~matplotlib.pyplot.clf`
251+
.. and the current axes with :func:`~matplotlib.pyplot.cla`. If you find
252+
.. this statefulness, annoying, don't despair, this is just a thin
253+
.. stateful wrapper around an object oriented API, which you can use
254+
.. instead (see :ref:`artist-tutorial`)
255+
256+
.. If you are making a long sequence of figures, you need to be aware of one
257+
.. more thing: the memory required for a figure is not completely
258+
.. released until the figure is explicitly closed with
259+
.. :func:`~matplotlib.pyplot.close`. Deleting all references to the
260+
.. figure, and/or using the window manager to kill the window in which
261+
.. the figure appears on the screen, is not enough, because pyplot
262+
.. maintains internal references until :func:`~matplotlib.pyplot.close`
263+
.. is called.
264+
265+
.. .. _working-with-text:
266+
267+
.. Working with text
268+
.. =================
269+
270+
.. The :func:`~matplotlib.pyplot.text` command can be used to add text in
271+
.. an arbitrary location, and the :func:`~matplotlib.pyplot.xlabel`,
272+
.. :func:`~matplotlib.pyplot.ylabel` and :func:`~matplotlib.pyplot.title`
273+
.. are used to add text in the indicated locations (see :ref:`text-intro`
274+
.. for a more detailed example)
275+
276+
.. .. plot:: pyplots/pyplot_text.py
277+
.. :include-source:
278+
279+
280+
.. All of the :func:`~matplotlib.pyplot.text` commands return an
281+
.. :class:`matplotlib.text.Text` instance. Just as with with lines
282+
.. above, you can customize the properties by passing keyword arguments
283+
.. into the text functions or using :func:`~matplotlib.pyplot.setp`::
284+
285+
.. t = plt.xlabel('my data', fontsize=14, color='red')
286+
287+
.. These properties are covered in more detail in :ref:`text-properties`.
288+
289+
290+
.. Using mathematical expressions in text
291+
.. --------------------------------------
292+
293+
.. matplotlib accepts TeX equation expressions in any text expression.
294+
.. For example to write the expression :math:`\sigma_i=15` in the title,
295+
.. you can write a TeX expression surrounded by dollar signs::
296+
297+
.. plt.title(r'$\sigma_i=15$')
298+
299+
.. The ``r`` preceding the title string is important -- it signifies
300+
.. that the string is a *raw* string and not to treat backslashes as
301+
.. python escapes. matplotlib has a built-in TeX expression parser and
302+
.. layout engine, and ships its own math fonts -- for details see
303+
.. :ref:`mathtext-tutorial`. Thus you can use mathematical text across platforms
304+
.. without requiring a TeX installation. For those who have LaTeX and
305+
.. dvipng installed, you can also use LaTeX to format your text and
306+
.. incorporate the output directly into your display figures or saved
307+
.. postscript -- see :ref:`usetex-tutorial`.
308+
309+
310+
.. Annotating text
311+
.. ---------------
312+
313+
.. The uses of the basic :func:`~matplotlib.pyplot.text` command above
314+
.. place text at an arbitrary position on the Axes. A common use case of
315+
.. text is to annotate some feature of the plot, and the
316+
.. :func:`~matplotlib.pyplot.annotate` method provides helper
317+
.. functionality to make annotations easy. In an annotation, there are
318+
.. two points to consider: the location being annotated represented by
319+
.. the argument ``xy`` and the location of the text ``xytext``. Both of
320+
.. these arguments are ``(x,y)`` tuples.
321+
322+
.. .. plot:: pyplots/pyplot_annotate.py
323+
.. :include-source:
324+
325+
.. In this basic example, both the ``xy`` (arrow tip) and ``xytext``
326+
.. locations (text location) are in data coordinates. There are a
327+
.. variety of other coordinate systems one can choose -- see
328+
.. :ref:`annotations-tutorial` and :ref:`plotting-guide-annotation` for
329+
.. details. More examples can be found in
330+
.. :ref:`pylab_examples-annotation_demo`.

0 commit comments

Comments
 (0)