8000 DOC: add ScalarFormatter plot, other tweaks to dflt_style_changes · matplotlib/matplotlib@bc10d6d · GitHub
[go: up one dir, main page]

Skip to content

Commit bc10d6d

Browse files
committed
DOC: add ScalarFormatter plot, other tweaks to dflt_style_changes
This includes some reorganization of sections.
1 parent 9aa02c6 commit bc10d6d

File tree

1 file changed

+106
-69
lines changed

1 file changed

+106
-69
lines changed

doc/users/dflt_style_changes.rst

Lines changed: 106 additions & 69 deletions
< 67ED /tr>
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ The colors in the default property cycle have been changed from
3737

3838
.. plot::
3939

40+
import numpy as np
41+
import matplotlib.pyplot as plt
4042

4143
th = np.linspace(0, 2*np.pi, 512)
4244

@@ -113,17 +115,19 @@ The new default color map used by `matplotlib.cm.ScalarMappable` instances is
113115
.. plot::
114116

115117
import numpy as np
118+
import matplotlib.pyplot as plt
119+
116120
N = M = 200
117121
X, Y = np.ogrid[0:20:N*1j, 0:20:M*1j]
118122
data = np.sin(np.pi * X*2 / 20) * np.cos(np.pi * Y*2 / 20)
119123

120124
fig, (ax2, ax1) = plt.subplots(1, 2, figsize=(7, 3))
121125
im = ax1.imshow(data, extent=[0, 200, 0, 200])
122126
ax1.set_title("v2.0: 'viridis'")
123-
fig.colorbar(im, ax=ax1, shrink=.9)
127+
fig.colorbar(im, ax=ax1, shrink=0.8)
124128

125129
im2 = ax2.imshow(data, extent=[0, 200, 0, 200], cmap='jet')
126-
fig.colorbar(im2, ax=ax2, shrink=.9)
130+
fig.colorbar(im2, ax=ax2, shrink=0.8)
127131
ax2.set_title("classic: 'jet'")
128132

129133
fig.tight_layout()
@@ -180,6 +184,9 @@ solid light grey lines.
180184

181185
.. plot::
182186

187+
import numpy as np
188+
import matplotlib.pyplot as plt
189+
183190
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3))
184191

185192
ax1.grid(color='k', linewidth=.5, linestyle=':')
@@ -263,6 +270,9 @@ The following changes were made to the default behavior of
263270

264271
.. plot::
265272

273+
import numpy as np
274+
import matplotlib.pyplot as plt
275+
266276
np.random.seed(2)
267277

268278
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3))
@@ -408,7 +418,7 @@ in your :file:`matplotlibrc` file.
408418
``boxplot``
409419
-----------
410420

411-
Previously, boxplots were composed of a mish-mash styles that were, for
421+
Previously, boxplots were composed of a mish-mash of styles that were, for
412422
better for worse, inherited from Matlab. Most of the elements were blue,
413423
but the medians were red. The fliers (outliers) were black plus-symbols
414424
(`+`) and the whiskers were dashed lines, which created ambiguity if
@@ -422,6 +432,9 @@ obscuring data too much.
422432

423433
.. plot::
424434

435+
import numpy as np
436+
import matplotlib.pyplot as plt
437+
425438
data = np.random.lognormal(size=(37, 4))
426439
fig, (old, new) = plt.subplots(ncols=2, sharey=True)
427440
with plt.style.context('default'):
@@ -487,6 +500,7 @@ cycle.
487500
import numpy as np
488501

489502
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3))
503+
fig.subplots_adjust(wspace=0.3)
490504
th = np.linspace(0, 2*np.pi, 128)
491505
N = 5
492506

@@ -730,7 +744,7 @@ Legends
730744
=======
731745

732746
- By default, the number of points displayed in a legend is now 1.
733-
- The default legend location is ``best``, so the legend will be
747+
- The default legend location is ``'best'``, so the legend will be
734748
automatically placed in a location to minimize overlap with data.
735749
- The legend defaults now include rounded corners, a lighter
736750
boundary, and partially transparent boundary and background.
@@ -856,7 +870,7 @@ RGB space. This ensures that only colors from the color map appear
856870
in the final image. (If your viewer subsequently resamples the image,
857871
the artifact may reappear.)
858872

859-
The previous behavior can not be restored.
873+
The previous behavior cannot be restored.
860874

861875

862876
Shading
@@ -870,6 +884,67 @@ Shading
870884
Plot layout
871885
===========
872886

887+
Auto limits
888+
-----------
889+
890+
The previous auto-scaling behavior was to find 'nice' round numbers
891+
as view limits that enclosed the data limits, but this could produce
892+
bad plots if the data happened to fall on a vertical or
893+
horizontal line near the chosen 'round number' limit. The new default
894+
sets the view limits to 5% wider than the data range.
895+
896+
.. plot::
897+
898+
import matplotlib as mpl
899+
import matplotlib.pyplot as plt
900+
import numpy
901+
902+
data = np.zeros(1000)
903+
data[0] = 1
904+
905+
fig = plt.figure(figsize=(6, 3))
906+
907+
def demo(fig, rc, title, j):
908+
with mpl.rc_context(rc=rc):
909+
ax = fig.add_subplot(1, 2, j)
910+
ax.plot(data)
911+
ax.set_title(title)
912+
913+
demo(fig, {'axes.autolimit_mode': 'round_numbers',
914+
'axes.xmargin': 0,
915+
'axes.ymargin': 0}, 'classic', 1)
916+
demo(fig, {}, 'v2.0', 2)
917+
918+
The size of the padding in the x and y directions is controlled by the
919+
``'axes.xmargin'`` and ``'axes.ymargin'`` rcParams respectively. Whether
920+
the view limits should be 'round numbers' is controlled by the
921+
``'axes.autolimit_mode'`` rcParam. In the original ``'round_number'`` mode,
922+
the view limits coincide with ticks.
923+
924+
The previous default can be restored by using::
925+
926+
mpl.rcParams['axes.autolimit_mode'] = 'round_numbers'
927+
mpl.rcParams['axes.xmargin'] = 0
928+
mpl.rcParams['axes.ymargin'] = 0
929+
930+
or setting::
931+
932+
axes.autolimit_mode: round_numbers
933+
axes.xmargin: 0
934+
axes.ymargin: 0
935+
936+
in your :file:`matplotlibrc` file.
937+
938+
939+
Z-order
940+
-------
941+
942+
- Ticks and grids are now plotted above solid elements such as
943+
filled contours, but below lines. To return to the previous
944+
behavior of plotting ticks and grids above lines, set
945+
``rcParams['axes.axisbelow'] = False``.
946+
947+
873948
Ticks
874949
-----
875950

@@ -986,70 +1061,11 @@ case of the AutoLocator, the heuristic algorithm reduces the
9861061
incidence of overlapping tick labels but does not prevent it.
9871062

9881063

989-
Auto limits
990-
-----------
991-
992-
The previous auto-scaling behavior was to find 'nice' round numbers
993-
as view limits that enclosed the data limits, but this could produce
994-
bad plots if the data happened to fall on a vertical or
995-
horizontal line near the chosen 'round number' limit. The new default
996-
sets the view limits to 5% wider than the data range.
997-
998-
.. plot::
999-
1000-
import matplotlib as mpl
1001-
import matplotlib.pyplot as plt
1002-
import numpy
1003-
1004-
data = np.zeros(1000)
1005-
data[0] = 1
1006-
1007-
fig = plt.figure(figsize=(6, 3))
1008-
1009-
def demo(fig, rc, title, j):
1010-
with mpl.rc_context(rc=rc):
1011-
ax = fig.add_subplot(1, 2, j)
1012-
ax.plot(data)
1013-
ax.set_title(title)
1014-
1015-
demo(fig, {'axes.autolimit_mode': 'round_numbers',
1016-
'axes.xmargin': 0,
1017-
'axes.ymargin': 0}, 'classic', 1)
1018-
demo(fig, {}, 'v2.0', 2)
1019-
1020-
The size of the padding in the x and y directions is controlled by the
1021-
``'axes.xmargin'`` and ``'axes.ymargin'`` rcParams respectively. Whether
1022-
the view limits should be 'round numbers' is controlled by the
1023-
``'axes.autolimit_mode'`` rcParam. In the original ``'round_number'`` mode,
1024-
the view limits coincide with ticks.
1025-
1026-
The previous default can be restored by using::
1027-
1028-
mpl.rcParams['axes.autolimit_mode'] = 'round_numbers'
1029-
mpl.rcParams['axes.xmargin'] = 0
1030-
mpl.rcParams['axes.ymargin'] = 0
1031-
1032-
or setting::
1033-
1034-
axes.autolimit_mode: round_numbers
1035-
axes.xmargin: 0
1036-
axes.ymargin: 0
1037-
1038-
in your :file:`matplotlibrc` file.
1039-
1040-
1041-
1042-
Z-order
1043-
-------
1044-
1045-
- Ticks and grids are now plotted above solid elements such as
1046-
filled contours, but below lines. To return to the previous
1047-
behavior of plotting ticks and grids above lines, set
1048-
``rcParams['axes.axisbelow'] = False``.
1049-
1064+
Tick label formatting
1065+
---------------------
10501066

10511067
``LogFormatter`` labeling of minor ticks
1052-
========================================
1068+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10531069

10541070
Minor ticks on a log axis are now labeled when the axis view limits
10551071
span a range less than or equal to the interval between two major
@@ -1081,18 +1097,39 @@ but cannot be controlled independently via ``rcParams``.
10811097

10821098

10831099
``ScalarFormatter`` tick label formatting with offsets
1084-
======================================================
1100+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10851101

10861102
With the default of ``rcParams['axes.formatter.useoffset'] = True``,
10871103
an offset will be used when it will save 4 or more digits. This can
10881104
be controlled with the new rcParam, ``axes.formatter.offset_threshold``.
10891105
To restore the previous behavior of using an offset to save 2 or more
10901106
digits, use ``rcParams['axes.formatter.offset_threshold'] = 2``.
10911107

1108+
.. plot::
1109+
1110+
import numpy as np
1111+
import matplotlib.pyplot as plt
1112+
1113+
np.random.seed(5)
1114+
1115+
fig = plt.figure(figsize=(6, 3))
1116+
fig.subplots_adjust(bottom=0.15, wspace=0.3, left=0.09, right=0.95)
1117+
1118+
x = np.linspace(2000, 2008, 9)
1119+
y = np.random.randn(9) + 50000
1120+
1121+
with plt.rc_context(rc={'axes.formatter.offset_threshold' : 2}):
1122+
ax1 = fig.add_subplot(1, 2, 1)
1123+
ax1.plot(x, y)
1124+
ax1.set_title('classic')
1125+
1126+
ax2 = fig.add_subplot(1, 2, 2)
1127+
ax2.plot(x, y)
1128+
ax2.set_title('v2.0')
10921129

10931130

10941131
``AutoDateFormatter`` format strings
1095-
====================================
1132+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10961133

10971134
The default date formats are now all based on ISO format, i.e., with
10981135
the slowest-moving value first. The date formatters are

0 commit comments

Comments
 (0)
0