Discussion:
[Tutor] Shading Between Curves with Different Colour Over Specified X value Range
Colin Ross
2015-07-27 18:47:42 UTC
Permalink
*Goal:* Shade between I_2 (curve 1) and I_3 (curve 2) with following
conditions:
- Green for 0 < x < 4
- Red for 4 < x < 12

*Code: *

*Note: Code currently only attempting to shade green for 0 < x < 4 *

import numpy as np
import pylab
from pylab import *
import matplotlib.pyplot as plt
import csv


# Load data from .txt file

with open('current_mirror_output_swing.csv', 'rb') as f:
reader = csv.reader(f)
your_list = list(reader)

data = np.asarray(your_list)

I_ref = np.asarray(data[1:,0])
I_1 = data[1:,1]
I_2 = data[1:,2]
I_3 = data[1:,3]

# Create an array of x values to fill b/w curves with a certain color.

X1 = np.linspace(0.,4.,len(I_3))

I_ref = I_ref.astype(float)*1000.
I_1 = I_1.astype(float)*1000.
I_2 = I_2.astype(float)*1000.
I_3 = I_3.astype(float)*1000.


# Plotting commands.

plot(I_ref, I_2, 'r-')
plot(I_ref, I_3, 'b-')
title('Current Mirror Output Swing')
xlabel('$I_{ref}$ (mA)')
ylabel('I (mA)')

plt.fill_between(X1, I_2, I_3, color = 'g', alpha = '0.5')
plt.legend(['$I_{ref}$', '$I_{out}$'], loc='upper left')
plt.grid()

show()

*Issue: *

See attached figure.

Thank you.
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Mark Lawrence
2015-07-27 20:01:46 UTC
Permalink
Post by Colin Ross
*Goal:* Shade between I_2 (curve 1) and I_3 (curve 2) with following
- Green for 0 < x < 4
- Red for 4 < x < 12
*Code: *
*Note: Code currently only attempting to shade green for 0 < x < 4 *
import numpy as np
import pylab
from pylab import *
import matplotlib.pyplot as plt
import csv
# Load data from .txt file
reader = csv.reader(f)
your_list = list(reader)
data = np.asarray(your_list)
I_ref = np.asarray(data[1:,0])
I_1 = data[1:,1]
I_2 = data[1:,2]
I_3 = data[1:,3]
# Create an array of x values to fill b/w curves with a certain color.
X1 = np.linspace(0.,4.,len(I_3))
I_ref = I_ref.astype(float)*1000.
I_1 = I_1.astype(float)*1000.
I_2 = I_2.astype(float)*1000.
I_3 = I_3.astype(float)*1000.
# Plotting commands.
plot(I_ref, I_2, 'r-')
plot(I_ref, I_3, 'b-')
title('Current Mirror Output Swing')
xlabel('$I_{ref}$ (mA)')
ylabel('I (mA)')
plt.fill_between(X1, I_2, I_3, color = 'g', alpha = '0.5')
plt.legend(['$I_{ref}$', '$I_{out}$'], loc='upper left')
plt.grid()
show()
*Issue: *
See attached figure.
Thank you.
There is no attachment to see, sorry :(

One thing to note about the following lines.

from pylab import *
import matplotlib.pyplot as plt

The first was designed to make matplotlib easy to use interactively,
especially in iPython, the second in a script. IIRC the former is
deprecated so I suggest you stick with the latter.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Colin Ross
2015-07-28 00:00:16 UTC
Permalink
Post by Mark Lawrence
Post by Colin Ross
*Goal:* Shade between I_2 (curve 1) and I_3 (curve 2) with following
- Green for 0 < x < 4
- Red for 4 < x < 12
*Code: *
*Note: Code currently only attempting to shade green for 0 < x < 4 *
import numpy as np
import pylab
from pylab import *
import matplotlib.pyplot as plt
import csv
# Load data from .txt file
reader = csv.reader(f)
your_list = list(reader)
data = np.asarray(your_list)
I_ref = np.asarray(data[1:,0])
I_1 = data[1:,1]
I_2 = data[1:,2]
I_3 = data[1:,3]
# Create an array of x values to fill b/w curves with a certain color.
X1 = np.linspace(0.,4.,len(I_3))
I_ref = I_ref.astype(float)*1000.
I_1 = I_1.astype(float)*1000.
I_2 = I_2.astype(float)*1000.
I_3 = I_3.astype(float)*1000.
# Plotting commands.
plot(I_ref, I_2, 'r-')
plot(I_ref, I_3, 'b-')
title('Current Mirror Output Swing')
xlabel('$I_{ref}$ (mA)')
ylabel('I (mA)')
plt.fill_between(X1, I_2, I_3, color = 'g', alpha = '0.5')
plt.legend(['$I_{ref}$', '$I_{out}$'], loc='upper left')
plt.grid()
show()
*Issue: *
See attached figure.
Thank you.
There is no attachment to see, sorry :(
My apologies. SHould be there now!
Post by Mark Lawrence
One thing to note about the following lines.
from pylab import *
import matplotlib.pyplot as plt
The first was designed to make matplotlib easy to use interactively,
especially in iPython, the second in a script. IIRC the former is
deprecated so I suggest you stick with the latter.
Great, thank you!
Post by Mark Lawrence
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Alan Gauld
2015-07-28 09:13:49 UTC
Permalink
Post by Colin Ross
Post by Mark Lawrence
Post by Colin Ross
*Issue: *
See attached figure.
Thank you.
There is no attachment to see, sorry :(
My apologies. SHould be there now!
The problem is a lot of mailing list servers (and even some
corporate mail servers) strip off attachments. In this case
I still can't see one so something between you and me is
stripping it. It may even be that some people will see it
and others don't.

For that reason it's usually better if you have access to
some web space to post the image there and provide a URL.
Or at least provide a textual description for those who
can't see the image.

hth
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Colin Ross
2015-07-28 11:18:36 UTC
Permalink
Post by Colin Ross
*Issue: *
Post by Colin Ross
Post by Mark Lawrence
Post by Colin Ross
See attached figure.
Thank you.
There is no attachment to see, sorry :(
My apologies. SHould be there now!
The problem is a lot of mailing list servers (and even some
corporate mail servers) strip off attachments. In this case
I still can't see one so something between you and me is
stripping it. It may even be that some people will see it
and others don't.
For that reason it's usually better if you have access to
some web space to post the image there and provide a URL.
Or at least provide a textual description for those who
can't see the image.
hth
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
http://www.flickr.com/photos/alangauldphotos
It appears to be taking the entire area between the two curves and
compressing it between the specified x values. When I specify the entire x
range, the shaded area fits between the two curves perfectly. However, when
I specify a smaller range of x values, the shape of the area between the
two curves appears to be elongated vertically as though it is trying to
squeeze the total area into the smaller x range (i.e. it does not follow
the upper and lower limits anymore). I hope this makes sense, I will try
and post a URL...
Post by Colin Ross
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Oscar Benjamin
2015-07-28 14:03:48 UTC
Permalink
Post by Colin Ross
*Goal:* Shade between I_2 (curve 1) and I_3 (curve 2) with following
- Green for 0 < x < 4
- Red for 4 < x < 12
*Code: *
*Note: Code currently only attempting to shade green for 0 < x < 4 *
import numpy as np
import pylab
from pylab import *
import matplotlib.pyplot as plt
import csv
# Load data from .txt file
reader = csv.reader(f)
your_list = list(reader)
data = np.asarray(your_list)
I_ref = np.asarray(data[1:,0])
I_1 = data[1:,1]
I_2 = data[1:,2]
I_3 = data[1:,3]
# Create an array of x values to fill b/w curves with a certain color.
X1 = np.linspace(0.,4.,len(I_3))
I_ref = I_ref.astype(float)*1000.
I_1 = I_1.astype(float)*1000.
I_2 = I_2.astype(float)*1000.
I_3 = I_3.astype(float)*1000.
# Plotting commands.
Here you specify the X values for the line plots as being whatever I_ref is
Post by Colin Ross
plot(I_ref, I_2, 'r-')
plot(I_ref, I_3, 'b-')
title('Current Mirror Output Swing')
xlabel('$I_{ref}$ (mA)')
ylabel('I (mA)')
plt.fill_between(X1, I_2, I_3, color = 'g', alpha = '0.5')
to:

plt.fill_between(I_ref, I_2, I_3, color = 'g', alpha = '0.5')

and then the filled area should have the same X range as the lines.

--
Oscar
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Colin Ross
2015-07-29 15:33:21 UTC
Permalink
Post by Oscar Benjamin
Post by Colin Ross
*Goal:* Shade between I_2 (curve 1) and I_3 (curve 2) with following
- Green for 0 < x < 4
- Red for 4 < x < 12
*Code: *
*Note: Code currently only attempting to shade green for 0 < x < 4 *
import numpy as np
import pylab
from pylab import *
import matplotlib.pyplot as plt
import csv
# Load data from .txt file
reader = csv.reader(f)
your_list = list(reader)
data = np.asarray(your_list)
I_ref = np.asarray(data[1:,0])
I_1 = data[1:,1]
I_2 = data[1:,2]
I_3 = data[1:,3]
# Create an array of x values to fill b/w curves with a certain color.
X1 = np.linspace(0.,4.,len(I_3))
I_ref = I_ref.astype(float)*1000.
I_1 = I_1.astype(float)*1000.
I_2 = I_2.astype(float)*1000.
I_3 = I_3.astype(float)*1000.
# Plotting commands.
Here you specify the X values for the line plots as being whatever I_ref
Post by Colin Ross
plot(I_ref, I_2, 'r-')
plot(I_ref, I_3, 'b-')
title('Current Mirror Output Swing')
xlabel('$I_{ref}$ (mA)')
ylabel('I (mA)')
plt.fill_between(X1, I_2, I_3, color = 'g', alpha = '0.5')
plt.fill_between(I_ref, I_2, I_3, color = 'g', alpha = '0.5')
and then the filled area should have the same X range as the lines.
--
Oscar
Thanks! This works now.
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Loading...