[Tutor] Shading Between Curves with Different Colour Over Specified X value Range

Colin Ross colin.ross.dal at gmail.com
Tue Jul 28 02:00:16 CEST 2015


On Mon, Jul 27, 2015 at 5:01 PM, Mark Lawrence <breamoreboy at yahoo.co.uk>
wrote:

> On 27/07/2015 19:47, Colin Ross wrote:
>
>> *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.
>>
>
> There is no attachment to see, sorry :(
>

My apologies. SHould be there now!


>
> 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!


>
>
> --
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
>
> Mark Lawrence
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list