jmvuilla / mywindstats

Source code of mywindstats.com
1 stars 0 forks source link

Windhistory - draw the wind speed curve with varying color, as a function of the wind direction #3

Open jmvuilla opened 7 years ago

jmvuilla commented 7 years ago

The current wind history graph shows the wind speed, with no information related to the wind direction.

Proposal is to combine wind speed & wind direction in a single plot, by using different colors, based on the wind direction. See http://stackoverflow.com/questions/8945699/gnuplot-linecolor-variable-in-matplotlib/18516488#18516488 for a possible solution.

jmvuilla commented 7 years ago

First working version, developed in a sandbox (outside GCP).

import matplotlib.pyplot import matplotlib.collections import numpy

x = numpy.array(range(20)) y = numpy.array([10,11,12,11,14,10,9,15,17,19,17,15,15,13,10,9,9,13,16,20]) z = numpy.array([0,0,0,340,350,10,45,90,90,90,45,22.5,0,270,292,22.5,45,45,0,0]) points = numpy.array([x,y]).T.reshape(-1,1,2) segments = numpy.concatenate([points[:-1], points[1:]], axis=1)

matplotlib.pyplot.title("Vitesse du vent a Lery-Poses") matplotlib.pyplot.xlabel('Temps') matplotlib.pyplot.ylabel('Vitesse (km/h)') matplotlib.pyplot.grid(True)

lc = matplotlib.collections.LineCollection(segments, cmap=matplotlib.pyplot.get_cmap('Spectral'),norm=matplotlib.pyplot.Normalize(0,360)) lc.set_array(z) lc.set_linewidth(2) matplotlib.pyplot.gca().add_collection(lc) matplotlib.pyplot.xlim(0,20) matplotlib.pyplot.ylim(0,25) cbar = matplotlib.pyplot.gcf().colorbar(lc,ticks=[0,45,90,135,180,225,270,315,360]) cbar.ax.set_yticklabels(['N','NE','E','SE','S','SO','O','NO','N']) cbar.set_label('Direction du vent (en degres)')

matplotlib.pyplot.show()

jmvuilla commented 7 years ago

screenshotproto

jmvuilla commented 7 years ago

Might want to show the colorbar as a circle iso a simple bar.