Skip to content

step-between as drawstyle [Alternative approach to #15019] #15065

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

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c670099
Add where="between"/"edges" to step and step="between" to fill_between
andrzejnovak Aug 28, 2019
f9d9d43
Protect for scalars in fill_between
andrzejnovak Aug 28, 2019
723dcdd
Fix fill_between input handling
andrzejnovak Aug 28, 2019
4e464eb
clean up
andrzejnovak Aug 28, 2019
ce9fbe4
Add svg
andrzejnovak Aug 29, 2019
138d14c
Add fill between step test
andrzejnovak Aug 29, 2019
028d618
Fallback to post-step, when x,y equal len
andrzejnovak Aug 29, 2019
aab6c1b
Protect "edges" from Nan values
andrzejnovak Sep 16, 2019
babca7e
Fix subslicing, add test at edges
andrzejnovak Sep 19, 2019
5f70d07
Switch broadcasting back to np
andrzejnovak Sep 19, 2019
46c2263
Improve example
andrzejnovak Sep 19, 2019
5264dea
Update docs
andrzejnovak Sep 20, 2019
7ed54a6
Clean for speedup
andrzejnovak Sep 28, 2019
b0a6244
Pad where True
andrzejnovak Sep 28, 2019
bf04d4c
Merge branch 'master' into ModLine2D
andrzejnovak Dec 4, 2019
f9634b2
Merge branch 'master' into ModLine2D
andrzejnovak Dec 5, 2019
65f0282
Undo redundant padding
andrzejnovak Jan 2, 2020
9cc16c1
paddding not needed
andrzejnovak Jan 2, 2020
814f180
flake
andrzejnovak Jan 3, 2020
ce92ba5
Merge branch 'master' into ModLine2D
andrzejnovak Jan 3, 2020
8b08a8e
flake
andrzejnovak Jan 3, 2020
3b73e4f
Simplify between-step
andrzejnovak Jan 6, 2020
0d9dec7
flake
andrzejnovak Jan 6, 2020
ef10ca4
Merge branch 'master' into ModLine2D
andrzejnovak Jan 6, 2020
72598d6
Try to fix docs
andrzejnovak Jan 6, 2020
bc3b19b
flake
andrzejnovak Jan 7, 2020
dbc3e92
Merge branch 'master' into ModLine2D
andrzejnovak Jan 7, 2020
80c348b
no np.r_
andrzejnovak Jan 7, 2020
023ebe3
whitespace
andrzejnovak Jan 7, 2020
290be4a
Fix typos
andrzejnovak Jan 13, 2020
46791b7
Externalize polycollection prep into cbook
andrzejnovak Mar 6, 2020
1989735
Fix name
andrzejnovak Mar 6, 2020
94799fd
Merge branch 'master' into ModLine2D
andrzejnovak Mar 6, 2020
c26aa11
flake
andrzejnovak Mar 6, 2020
b4cae0d
private
andrzejnovak Mar 7, 2020
3fd3b43
private
andrzejnovak Mar 7, 2020
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
22 changes: 22 additions & 0 deletions doc/users/next_whats_new/option_between_for_step_fill_between.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
New drawstyles for steps - "steps-between", "steps-edges"
------------------------------------------------------------------------
They are asymmetrical such that abs(len(x) - len(y)) == 1. Typically
to enable plotting histograms with step() and fill_between().

.. plot::

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0,7,1)
y = np.array([2,3,4,5,4,3])

fig, ax = plt.subplots(constrained_layout=True)

ax.plot(x, y + 2, drawstyle='steps-between')
ax.plot(x, y, drawstyle='steps-edges')

plt.show()

See :doc:`/gallery/lines_bars_and_markers/step_demo` and
:doc:`/gallery/lines_bars_and_markers/filled_step` for examples.
28 changes: 26 additions & 2 deletions examples/lines_bars_and_markers/filled_step.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
=========================
Hatch-filled histograms
Filled histograms
=========================

Hatching capabilities for plotting histograms.
Filled histograms and hatching capabilities for plotting histograms.
"""

import itertools
Expand All @@ -15,6 +15,30 @@
import matplotlib.ticker as mticker
from cycler import cycler

###############################################################################
# Plain filled steps

# sphinx_gallery_thumbnail_number = 2

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9, 4.5), tight_layout=True)
ax1.fill_between([0, 1, 2, 3], [1, 2, 3], step='between')
ax2.fill_betweenx([0, 1, 2, 3], [0, 1, 2], step='between')
ax1.set_ylabel('counts')
ax1.set_xlabel('edges')
ax2.set_xlabel('counts')
ax2.set_ylabel('edges')

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9, 4.5), tight_layout=True)
ax1.fill_between([0, 1, 2, 3], [1, 2, 3], [0, 1, 0], step='between')
ax2.fill_betweenx([0, 1, 2, 3], [1, 2, 3], [0, 1, 0], step='between')
ax1.set_ylabel('counts')
ax1.set_xlabel('edges')
ax2.set_xlabel('counts')
ax2.set_ylabel('edges')


###############################################################################
# Hatches

def filled_hist(ax, edges, values, bottoms=None, orientation='v',
**kwargs):
Expand Down
14 changes: 14 additions & 0 deletions examples/lines_bars_and_markers/step_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@
plt.title('plt.plot(drawstyle=...)')
plt.show()

# Plotting with where='between'/'edges'
x = np.arange(0, 7, 1)
y = np.array([2, 3, 4, 5, 4, 3])

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5))
ax1.step(x, y + 2, where='between', label='between')
ax1.step(x, y, where='edges', label='edges')
ax1.legend(title='Parameter where:')

ax2.step(y + 2, x, where='between', label='between')
ax2.step(y, x, where='edges', label='edges')
ax2.legend(title='Parameter where:')

plt.show()
#############################################################################
#
# ------------
Expand Down
Loading