Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Load Duration Curves in Matplotlib

I'm trying to plot a load duration curve in matplotlib. A load duration curve is basically a sorted list of numbers from high to low on the y axis and an index which usually represents time in hours. I am having trouble plotting the numbers from high to low. Matplotlib is plotting them from low to high even though I have sorted the list. My code is below:

meter_data = data_dictionary[key]
loading = get_loading_curve(key,time_series,meter_data)
loading.sort(reverse=True)
percent_loading = 100*numpy.array(loading)
meter_data.sort(reverse=True)
meter_data = numpy.array(meter_data)
print meter_data
l = len(meter_data)
index = numpy.array(range(0,l))

I'm trying to plot meter_data on the y axis and index on the x axis. meter_data should be sorted high to low, so the high values should show up on the left side of the graph and descend. The print statement in the above code shows an numpy array that has the highest values first.

I then go to plot this:

ax = fig.add_subplot(2,2,1)
plt.plot(index,meter_data)
plt.title('Hours vs. Load',size = 14,color = 'g')
plt.xlabel('Hours',size = 12)
plt.ylabel('MVA',size = 12)
plt.grid(b = True,which = 'major',color ='k',linestyle = '-')
plt.minorticks_on()
plt.grid(b = True,which = 'minor',axis = 'y',color ='r',linestyle = ':')

But I end up getting the plot in reverse, it plots it from low to high not high to low. I'll see if I can get a photo up later, for some reason, I'm not able to post photos. It should look like this:

https://en.wikipedia.org/wiki/Load_duration_curve

I had this code near the top of my script

path = ' '
os.chdir(path)

I changed the path to move where PDF outputted. Before I added this code:

loading = get_loading_curve(key,time_series,meter_data)
loading.sort(reverse=True)
like image 506
bud Avatar asked May 14 '26 14:05

bud


1 Answers

Finally, I managed to figure out what was wrong and got the following output: enter image description here These are correct. I had changed the path:

path = ' '
os.chdir(path)

To output into a new location to test something. Forgot and ended up looking at plots that were wrong, because I plotted them before adding this code:

loading = get_loading_curve(key,time_series,meter_data)
loading.sort(reverse=True)

Therefore, I was looking at sorted but reverse = False. So they appeared backwards but in reality the correct graphs were being generated in another directory. The new working directory which I was not looking.

like image 65
bud Avatar answered May 17 '26 02:05

bud



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!