setp for bar() Elements

Hi All,

i am in need of set the properties of my bar() Element,
by using a slider.

For plots this looks like this:
self.plot = self.subplot1.plot(x,y)
setp(self.plot, xdata=new_x, ydata=new_y)

How to do this with this,
self.bar = self.subplot2.bar(x,y)

???

Any Hints ?

Regards Markus

It depends on what kinds of properties you want to set. For example,
you could set the facecolor with

  plt.setp(self.bar, facecolor='red')

But I would advise you against this method of coding -- it's great for
simple interactive command line stuff, eg at the ipython prompt, but
it sounds like you are doing something a little more sophisticated and
would be better off plunging into the API. For example, you are
calling the matplotlib.axes.Axes.bar method (since your subplot2
instance is a Subplot which is an Axes subclass). So start with the
docs for Axes.bar

  http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.bar

You will see in the docstring that it says it returns a sequence of
Rectangle and has a link to the matplotlib.patches.Rectangle docs

  http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.patches.Rectangle

Those docs will show you all the properties (alpha, antialiased,
...facecolor, etc...) Each property has a link to the setter method.
So I advise something like

  # the names "self.rectangles" is better than "self.bar" IMO since
it describe whats kinds of mpl
  # object it are referring to
  self.rectangles = self.ax2.bar(something)
  for rectangle in self.rectangles:
      rectangle.set_alpha(0.4)
      rectangle.set_facecolor('green')

JDH

···

On Fri, May 22, 2009 at 5:17 AM, Markus Feldmann <feldmann_markus@...380...> wrote:

Hi All,

i am in need of set the properties of my bar() Element,
by using a slider.

For plots this looks like this:
self.plot = self.subplot1.plot(x,y)
setp(self.plot, xdata=new_x, ydata=new_y)

How to do this with this,
self.bar = self.subplot2.bar(x,y)

John Hunter schrieb:

  http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.patches.Rectangle

Those docs will show you all the properties (alpha, antialiased,
...facecolor, etc...) Each property has a link to the setter method.
So I advise something like

  # the names "self.rectangles" is better than "self.bar" IMO since
it describe whats kinds of mpl
  # object it are referring to
  self.rectangles = self.ax2.bar(something)
  for rectangle in self.rectangles:
      rectangle.set_alpha(0.4)
      rectangle.set_facecolor('green')

Thanks for your Answer,

i want to fill new xdata and new ydata to my bar() Elements.

in the docu there is something written of,
set_x()
set_y()

Is this of interest for me ?

My xdata and ydata are 1D Vectors like,
x = [1, 2, 4, 2, ...]
y = [1, 0, 0, 1, ...]

Regards Markus

Markus Feldmann schrieb:

in the docu there is something written of,
set_x()
set_y()

Is this of interest for me ?

My xdata and ydata are 1D Vectors like,
x = [1, 2, 4, 2, ...]
y = [1, 0, 0, 1, ...]

I tried,
self.bars[0].set_x(x)
self.bars[0].set_y[y]
where self.bars is a List containg my bar() Elements.
But this doesn't work and results in an error,
TypeError: 'instancemethod' object is unsubscriptable

Any Ideas ?

regards Markus

Yes, there is also a set_width and set_height method. between the x,
y, width and height, you can update the rectangle position.

JDH

···

On Fri, May 22, 2009 at 8:09 AM, Markus Feldmann <feldmann_markus@...380...> wrote:

i want to fill new xdata and new ydata to my bar() Elements.

in the docu there is something written of,
set_x()
set_y()

Is this of interest for me ?

try self.bars[0].set_y(y)

JDH

···

On Fri, May 22, 2009 at 8:42 AM, Markus Feldmann <feldmann_markus@...380...> wrote:

I tried,
self.bars[0].set_x(x)
self.bars[0].set_y[y]

John Hunter schrieb:

···

On Fri, May 22, 2009 at 8:42 AM, Markus Feldmann <feldmann_markus@...380...> wrote:

I tried,
self.bars[0].set_x(x)
self.bars[0].set_y[y]

try self.bars[0].set_y(y)

Thanks this corrects was my error.
I think you have eagle eyes. :slight_smile:

Regards markus