I figured it out on my own! Why I couldn't figure it out before... I don't
know...
Here is the code:
myhighlights[1].set_facecolor('y')
myhighlights[1].set_xy([[ 3.5 , 0. ],\
[ 3.5 , 1. ],
[ 3.75, 1. ],
[ 3.75, 0. ],
[ 3.5 , 0. ]])
KrishnaPribadi wrote:
>
> Hi,
> I added several axvspan "highlights on my plot.
>
> I'd like to change the properties of only one of those "highlights" such
> as the facecolor, xmin, and xmax. I've included some code below. Lets say
> I'd like to change the properties on the 2nd vertical highlight (axvspan).
>
> Can someone please suggest some code on accessing and changing properties
> on that specific object?
>
> do I access it from the object "myhighlights" or do I access is from the
> object "ax"?
>
> Note: This is just some simple code I came up with. My real application is
> in a wx app GUI so I will be using the draw() function.
>
> Here is my code:
> import numpy as np
> import matplotlib.pyplot as plt
>
>
> t = np.arange(0, np.pi*2, 0.01)
> x = np.sin(2*np.pi*t)
>
>
> fig = plt.figure()
> ax = fig.add_subplot(111)
> ax.grid('On')
>
> myplot = ax.plot(t, x, 'b')
>
> myhighlights = []
> myhighlights.append(ax.axvspan(1,2, facecolor='g', alpha=0.2))
> myhighlights.append(ax.axvspan(3,4, facecolor='g', alpha=0.2)) #later
> let's change the facecolor, xmin, and xmax
> myhighlights.append(ax.axvspan(5,6, facecolor='g', alpha=0.2))
>
> #need code to change properties of the 2nd axvspan
> #change facecolor to yellow
> #change xmin to 3.5 and xmax to 4.5
>
> plt.show()
>
-----
Krishna Adrianto Pribadi
Test Engineer
Harley-Davidson Motor Co.
Talladega Test Facility
Vehicle Test Stands
--
View this message in context: http://old.nabble.com/axvspan%2C-multiple-calls%2C-how-to-change-prop-of-1-object-instance-tp28219155p28219166.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
|