Markers on a matplotlib plot

B

Brandon La Porte

I have the following code to make a plot of 4 different supply curves (economics).


from matplotlib import pyplot as plt

price = range(0,51)
q1 = [x/2.0 for x in price]
q2 = [x/4.0 for x in price]
q3 = [x/5.0 for x in price]
q4 = [x/10.0 for x in price]

markers_on = [20, 40]

plt.plot(q1,price,'b',q2,price,'g',q3,price,'r', q4, price, 'y' )
plt.title('Supply Curve')
plt.xlabel('Quantity Supplied (Thousands per month')
plt.ylabel('Price ($)')
#plt.legend(('Kd = %d'%kd, 'Kd = %d'%kd2, 'Kd = %d'% kd3, 'Step'), loc=4)
plt.legend(('p = 2Qs', 'p = 4Qs', 'p = 5Qs', 'p = 10Qs'), loc=4)

plt.grid()
plt.show()

I would like to place markers on the 4 curves when the price is equal to $20 label it A, and when the price is equal to $40 and label it B. Does anyone know how I can accomplish this.
 
M

Mark Lawrence

I have the following code to make a plot of 4 different supply curves (economics).


from matplotlib import pyplot as plt

price = range(0,51)
q1 = [x/2.0 for x in price]
q2 = [x/4.0 for x in price]
q3 = [x/5.0 for x in price]
q4 = [x/10.0 for x in price]

markers_on = [20, 40]

plt.plot(q1,price,'b',q2,price,'g',q3,price,'r', q4, price, 'y' )
plt.title('Supply Curve')
plt.xlabel('Quantity Supplied (Thousands per month')
plt.ylabel('Price ($)')
#plt.legend(('Kd = %d'%kd, 'Kd = %d'%kd2, 'Kd = %d'% kd3, 'Step'), loc=4)
plt.legend(('p = 2Qs', 'p = 4Qs', 'p = 5Qs', 'p = 10Qs'), loc=4)

plt.grid()
plt.show()

I would like to place markers on the 4 curves when the price is equal to $20 label it A, and when the price is equal to $40 and label it B. Does anyone know how I can accomplish this.

If this matplotlib.pyplot.text described here
http://matplotlib.org/api/pyplot_api.html isn't any good I suggest you
ask on the dedicated matplotlib users mailing list see
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence
 
B

Brandon La Porte

I have the following code to make a plot of 4 different supply curves (economics).


from matplotlib import pyplot as plt

price = range(0,51)
q1 = [x/2.0 for x in price]
q2 = [x/4.0 for x in price]
q3 = [x/5.0 for x in price]
q4 = [x/10.0 for x in price]
markers_on = [20, 40]
plt.plot(q1,price,'b',q2,price,'g',q3,price,'r', q4, price, 'y' )
plt.title('Supply Curve')
plt.xlabel('Quantity Supplied (Thousands per month')
plt.ylabel('Price ($)')
#plt.legend(('Kd = %d'%kd, 'Kd = %d'%kd2, 'Kd = %d'% kd3, 'Step'), loc=4)
plt.legend(('p = 2Qs', 'p = 4Qs', 'p = 5Qs', 'p = 10Qs'), loc=4)




I would like to place markers on the 4 curves when the price is equal to $20 label it A, and when the price is equal to $40 and label it B. Does anyone know how I can accomplish this.



If this matplotlib.pyplot.text described here

http://matplotlib.org/api/pyplot_api.html isn't any good I suggest you

ask on the dedicated matplotlib users mailing list see

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



--

Roses are red,

Violets are blue,

Most poems rhyme,

But this one doesn't.



Mark Lawrence

Hi Mark

Thanks for the quick reply. I went through the documentation briefly and made some changes.

from matplotlib import pyplot as plt

q1 = 2.0
q2 = 4.0
q3 = 5.0
q4 = 10.0

p1 = 20
p2 = 40
price = range(0,51)
qlist1 = [x/q1 for x in price]
qlist2 = [x/q2 for x in price]
qlist3 = [x/q3 for x in price]
qlist4 = [x/q4 for x in price]


plt.plot(qlist1,price,'b',qlist2,price,'g',qlist3,price,'r', qlist4, price, 'y' )
plt.plot(p1/q1,p1,'ko', p1/q2, p1, 'ko', p1/q3,p1, 'ko', p1/q4, p1, 'ko')
plt.plot(p2/q1,p2,'ks', p2/q2, p2, 'ks', p2/q3,p2, 'ks', p2/q4, p2, 'ks')

plt.title('Supply Curve')
plt.xlabel('Quantity Supplied (Thousands per month)')
plt.ylabel('Price ($)')
plt.legend(('p = 2Qs', 'p = 4Qs', 'p = 5Qs', 'p = 10Qs'), loc=4)

plt.grid()
plt.show()


I'm sure there is a better or more "Pythonic" way to do this, and I still need to figure out how to label the individual points. Again thanks for the links, and I'll update this post when I figure it out.

Thanks
Brandon
 
M

Mark Lawrence

I have the following code to make a plot of 4 different supply curves (economics).


from matplotlib import pyplot as plt

price = range(0,51)
q1 = [x/2.0 for x in price]
q2 = [x/4.0 for x in price]
q3 = [x/5.0 for x in price]
q4 = [x/10.0 for x in price]
markers_on = [20, 40]
plt.plot(q1,price,'b',q2,price,'g',q3,price,'r', q4, price, 'y' )
plt.title('Supply Curve')
plt.xlabel('Quantity Supplied (Thousands per month')
plt.ylabel('Price ($)')
#plt.legend(('Kd = %d'%kd, 'Kd = %d'%kd2, 'Kd = %d'% kd3, 'Step'), loc=4)
plt.legend(('p = 2Qs', 'p = 4Qs', 'p = 5Qs', 'p = 10Qs'), loc=4)




I would like to place markers on the 4 curves when the price is equal to $20 label it A, and when the price is equal to $40 and label it B. Does anyone know how I can accomplish this.



If this matplotlib.pyplot.text described here

http://matplotlib.org/api/pyplot_api.html isn't any good I suggest you

ask on the dedicated matplotlib users mailing list see

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



--

Roses are red,

Violets are blue,

Most poems rhyme,

But this one doesn't.



Mark Lawrence

Hi Mark

Thanks for the quick reply. I went through the documentation briefly and made some changes.

from matplotlib import pyplot as plt

q1 = 2.0
q2 = 4.0
q3 = 5.0
q4 = 10.0

p1 = 20
p2 = 40
price = range(0,51)
qlist1 = [x/q1 for x in price]
qlist2 = [x/q2 for x in price]
qlist3 = [x/q3 for x in price]
qlist4 = [x/q4 for x in price]


plt.plot(qlist1,price,'b',qlist2,price,'g',qlist3,price,'r', qlist4, price, 'y' )
plt.plot(p1/q1,p1,'ko', p1/q2, p1, 'ko', p1/q3,p1, 'ko', p1/q4, p1, 'ko')
plt.plot(p2/q1,p2,'ks', p2/q2, p2, 'ks', p2/q3,p2, 'ks', p2/q4, p2, 'ks')

plt.title('Supply Curve')
plt.xlabel('Quantity Supplied (Thousands per month)')
plt.ylabel('Price ($)')
plt.legend(('p = 2Qs', 'p = 4Qs', 'p = 5Qs', 'p = 10Qs'), loc=4)

plt.grid()
plt.show()


I'm sure there is a better or more "Pythonic" way to do this, and I still need to figure out how to label the individual points. Again thanks for the links, and I'll update this post when I figure it out.

Thanks
Brandon

Fine, if you need more help I'll try but I'm no matplotlib expert, your
best bet is still its user mailing list.

Slight aside would you please read and action this link
https://wiki.python.org/moin/GoogleGroupsPython, a quick glance above
will tell you why, thanks :)

--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence
 
P

Piet van Oostrum

Brandon La Porte said:
I have the following code to make a plot of 4 different supply curves (economics).


from matplotlib import pyplot as plt

price = range(0,51)
q1 = [x/2.0 for x in price]
q2 = [x/4.0 for x in price]
q3 = [x/5.0 for x in price]
q4 = [x/10.0 for x in price]

markers_on = [20, 40]

plt.plot(q1,price,'b',q2,price,'g',q3,price,'r', q4, price, 'y' )
plt.title('Supply Curve')
plt.xlabel('Quantity Supplied (Thousands per month')
plt.ylabel('Price ($)')
#plt.legend(('Kd = %d'%kd, 'Kd = %d'%kd2, 'Kd = %d'% kd3, 'Step'), loc=4)
plt.legend(('p = 2Qs', 'p = 4Qs', 'p = 5Qs', 'p = 10Qs'), loc=4)

plt.grid()
plt.show()

I would like to place markers on the 4 curves when the price is equal to $20 label it A, and when the price is equal to $40 and label it B. Does anyone know how I can accomplish this.

Something like:

plt.plot(20,40, 'bo')
plt.annotate('B', (20,40), xytext=(-10,10), textcoords='offset points')

Of course you should write a loop to calculate the x, y points, and use the proper colors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top