filled step plot?

This has been asked before, and I just filed a ticket [1]. Can anyone think of a better way to do something like this? The fill_between below is pretty suboptimal IMO.

import matplotlib.pyplot as plt

import numpy as np

t_sec = np.arange(6)

velocity = np.array([24., 33., 40., 45., 48., 49.])

fig, ax = plt.subplots(figsize=(10,6))

lines = ax.plot(t_sec, velocity, ‘mo’)

ax.margins(.01)

ax.grid(False)

ax.set_ylim(0, 53);

steps = ax.step(t_sec, velocity, where=‘post’, color=‘black’)

filed = ax.fill_between(np.linspace(0, 5, 1001), 0, np.r_[np.repeat(velocity[:-1], 200), 5.])

Skipper

[1] https://github.com/matplotlib/matplotlib/issues/1709

Hi Skipper,

I think you are missing one bin in your plot… but anyway, this is how I’d do the same plot (filled step plot):

import matplotlib.pyplot as plt

import numpy as np

t_sec = np.arange(6)

velocity = np.array([24., 33., 40., 45., 48., 49.])

width = t_sec[1] - t_sec[0]

plt.bar(t_sec, velocity, width=width, facecolor=‘b’, edgecolor=’’)

xx = np.ravel(zip(t_sec, t_sec + width))

yy = np.ravel(zip(velocity, velocity))

plt.plot(xx, yy, ‘k’)

plt.show()

I think this is a bit simpler

Cheers,

Eduardo Banados

···

On Sun, Jan 27, 2013 at 12:35 AM, Skipper Seabold <jsseabold@…120…287…> wrote:

This has been asked before, and I just filed a ticket [1]. Can anyone think of a better way to do something like this? The fill_between below is pretty suboptimal IMO.

import matplotlib.pyplot as plt

import numpy as np

t_sec = np.arange(6)

velocity = np.array([24., 33., 40., 45., 48., 49.])

fig, ax = plt.subplots(figsize=(10,6))

lines = ax.plot(t_sec, velocity, ‘mo’)

ax.margins(.01)

ax.grid(False)

ax.set_ylim(0, 53);

steps = ax.step(t_sec, velocity, where=‘post’, color=‘black’)

filed = ax.fill_between(np.linspace(0, 5, 1001), 0, np.r_[np.repeat(velocity[:-1], 200), 5.])

Skipper

[1] https://github.com/matplotlib/matplotlib/issues/1709


Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,

MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current

with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft

MVPs and experts. ON SALE this month only – learn more at:

http://p.sf.net/sfu/learnnow-d2d


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Eduardo Bañados Torres

Hi,

···

Le 27/01/2013 00:35, Skipper Seabold a écrit :

This has been asked before, and I just filed a ticket [1]. Can anyone
think of a better way to do something like this? The fill_between
below is pretty suboptimal IMO.

I feel that adding a filled step plot would indeed be useful.

Just thinking at a possible API, would it make sense to add the
"drawstyle" argument which already exists for plot() to fill_between() ?

best,
Pierre