8000 DOC: Add additional plots to 3.9 what's new page · matplotlib/matplotlib@1d1b446 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1d1b446

Browse files
committed
DOC: Add additional plots to 3.9 what's new page
1 parent b242259 commit 1d1b446

File tree

1 file changed

+86
-13
lines changed

1 file changed

+86
-13
lines changed

doc/users/prev_whats_new/whats_new_3.9.0.rst

Lines changed: 86 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ Plotting and Annotation improvements
2222
Legend support for Boxplot
2323
--------------------------
2424

25-
Boxplots now support a *label* parameter to create legend entries.
26-
27-
Legend labels can be passed as a list of strings to label multiple boxes in a single
28-
`.Axes.boxplot` call:
29-
25+
Boxplots now support a *label* parameter to create legend entries. Legend labels can be
26+
passed as a list of strings to label multiple boxes in a single `.Axes.boxplot` call:
3027

3128
.. plot::
3229
:include-source:
@@ -119,21 +116,86 @@ Add option to plot only one half of violin plot
119116
-----------------------------------------------
120117

121118
Setting the parameter *side* to 'low' or 'high' allows to only plot one half of the
122-
violin plot.
119+
`.Axes.violinplot`.
120+
121+
.. plot::
122+
:include-source:
123+
:alt: Three copies of a vertical violin plot; first in blue showing the default of both sides, followed by an orange copy that only shows the "low" (or left, in this case) side, and finally a green copy that only shows the "high" (or right) side.
124+
125+
# Fake data with reproducible random state.
126+
np.random.seed(19680801)
127+
data = np.random.normal(0, 8, size=100)
128+
129+
fig, ax = plt.subplots()
130+
131+
ax.violinplot(data, [0], showmeans=True, showextrema=True)
132+
ax.violinplot(data, [1], showmeans=True, showextrema=True, side='low')
133+
ax.violinplot(data, [2], showmeans=True, showextrema=True, side='high')
134+
135+
ax.set_title('Violin Sides Example')
136+
ax.set_xticks([0, 1, 2], ['Default', 'side="low"', 'side="high"'])
137+
ax.set_yticklabels([])
123138

124139
``axhline`` and ``axhspan`` on polar axes
125140
-----------------------------------------
126141

127142
... now draw circles and circular arcs (`~.Axes.axhline`) or annuli and wedges
128143
(`~.Axes.axhspan`).
129144

145+
.. plot::
146+
:include-source:
147+
:alt: A sample polar plot, that contains an axhline at radius 1, an axhspan annulus between radius 0.8 and 0.9, and an axhspan wedge between radius 0.6 and 0.7 and 288° and 324°.
148+
149+
fig = plt.figure()
150+
ax = fig.add_subplot(projection="polar")
151+
ax.set_rlim(0, 1.2)
152+
153+
ax.axhline(1, c="C0", alpha=.5)
154+
ax.axhspan(.8, .9, fc="C1", alpha=.5)
155+
ax.axhspan(.6, .7, .8, .9, fc="C2", alpha=.5)
156+
130157
subplot titles can now be automatically aligned
131158
-----------------------------------------------
132159

133160
Subplot axes titles can be misaligned vertically if tick labels or xlabels are placed at
134-
the top of one subplot. The new method on the `.Figure` class: `.Figure.align_titles`
161+
the top of one subplot. The new `~.Figure.align_titles` method on the `.Figure` class
135162
will now align the titles vertically.
136163

164+
.. plot::
165+
:include-source:
166+
:alt: A figure with two Axes side-by-side, the second of which with ticks on top. The Axes titles and x-labels ppear unaligned with each other due to these ticks.
167+
168+
fig, axs = plt.subplots(1, 2, layout='constrained')
169+
170+
axs[0].plot(np.arange(0, 1e6, 1000))
171+
axs[0].set_title('Title 0')
172+
axs[0].set_xlabel('XLabel 0')
173+
174+
axs[1].plot(np.arange(1, 0, -0.1) * 2000, np.arange(1, 0, -0.1))
175+
axs[1].set_title('Title 1')
176+
axs[1].set_xlabel('XLabel 1')
177+
axs[1].xaxis.tick_top()
178+
axs[1].tick_params(axis='x', rotation=55)
179+
180+
.. plot::
181+
:include-source:
182+
:alt: A figure with two Axes side-by-side, the second of which with ticks on top. Unlike the previous figure, the Axes titles and x-labels appear aligned.
183+
184+
fig, axs = plt.subplots(1, 2, layout='constrained')
185+
186+
axs[0].plot(np.arange(0, 1e6, 1000))
187+
axs[0].set_title('Title 0')
188+
axs[0].set_xlabel('XLabel 0')
189+
190+
axs[1].plot(np.arange(1, 0, -0.1) * 2000, np.arange(1, 0, -0.1))
191+
axs[1].set_title('Title 1')
192+
axs[1].set_xlabel('XLabel 1')
193+
axs[1].xaxis.tick_top()
194+
axs[1].tick_params(axis='x', rotation=55)
195+
196+
fig.align_labels()
197+
fig.align_titles()
198+
137199
``axisartist`` can now be used together with standard ``Formatters``
138200
--------------------------------------------------------------------
139201

@@ -152,6 +214,17 @@ Minor ticks on an `~matplotlib.axis.Axis` can be displayed or removed using
152214
When formatting negative values, `.StrMethodFormatter` will now use unicode minus signs
153215
if :rc:`axes.unicode_minus` is set.
154216

217+
>>> from matplotlib.ticker import StrMethodFormatter
218+
>>> with plt.rc_context({'axes.unicode_minus': False}):
219+
... formatter = StrMethodFormatter('{x}')
220+
... print(formatter.format_data(-10))
221+
-10
222+
223+
>>> with plt.rc_context({'axes.unicode_minus': True}):
224+
... formatter = StrMethodFormatter('{x}')
225+
... print(formatter.format_data(-10))
226+
−10
227+
155228
Figure, Axes, and Legend Layout
156229
===============================
157230

@@ -182,9 +255,9 @@ default a zorder of 0.
182255
Getters for xmargin, ymargin and zmargin
183256
----------------------------------------
184257

185-
``.Axes.get_xmargin()``, ``.Axes.get_ymargin()`` and ``.Axes3D.get_zmargin()`` methods
186-
have been added to return the margin values set by ``.Axes.set_xmargin()``,
187-
``.Axes.set_ymargin()`` and ``.Axes3D.set_zmargin()``, respectively.
258+
`.Axes.get_xmargin`, `.Axes.get_ymargin` and `.Axes3D.get_zmargin` methods have been
259+
added to return the margin values set by `.Axes.set_xmargin`, `.Axes.set_ymargin` and
260+
`.Axes3D.set_zmargin`, respectively.
188261

189262
Mathtext improvements
190263
=====================
@@ -207,9 +280,9 @@ Widget Improvements
207280
Check and Radio Button widgets support clearing
208281
-----------------------------------------------
209282

210-
The `.CheckButtons` and `.RadioButtons` widgets now support clearing their
211-
state by calling their ``.clear`` method. Note that it is not possible to have
212-
no selected radio buttons, so the selected option at construction time is selected.
283+
The `.CheckButtons` and `.RadioButtons` widgets now support clearing their state by
284+
calling their ``.clear`` method. Note that it is not possible to have no selected radio
285+
buttons, so the selected option at construction time is selected.
213286

214287
3D plotting improvements
215288
========================

0 commit comments

Comments
 (0)
0