1

I am trying to plot wind roses in subplots by using the module windrose in python

https://pypi.python.org/pypi/windrose/

Apart from some examples there is not too much documentation so I do not know how to use it to plot different subplots of wind roses

My try quite summarized:

import pandas as pd
import matplotlib.pyplot as plt
from windrose import WindroseAxes
import matplotlib.cm as cm
from time import sleep

v=df.speed
d=df.direction
f = Figure(figsize=(16,9), dpi=60) 
a = f.add_subplot(131)
ax = WindroseAxes.from_ax()
a.set_axes(ax)
ax.bar(d,v, normed= True,opening=0.8, edgecolor='white')
ax.set_legend()

then b = f.add_subplot(132) .... and so on

My second question is,

Once I generate the plot I would like to introduce a pause with time.sleep() or something similar

I tried with a simple example in which:

  1. I plot something
  2. then export it to png format with f.savefig()
  3. then I introduce sleep(20)
  4. then the code continues

but although it exports the right png It is not displayed on the screen and the code continues. As it does not raise any error I suppose there is something missing I should add before or after sleep()

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
gis20
  • 1,024
  • 2
  • 15
  • 33

1 Answers1

1

First question: You can not put another figure to existing figure as subplot (unfortunately WindroseAxes.from_ax() create a new figure and does not change only axis instance).

If you write

fig = plt.figure(figsize=(16,9), dpi=60) 
wax = WindroseAxes.from_ax(fig=fig)
ax1 = fig.add_subplot(221)
wax.contourf(wd, ws, bins=np.arange(0, 8, 1), cmap=cm.hot)
wax.set_legend()
ax2 = fig.add_subplot(222)
ax2.plot([1,2,3,4], [1,4,9,16], 'k-')
ax3 = fig.add_subplot(223)
ax3.plot([1,2,3,4], [1,10,100,1000], 'b-')
ax4 = fig.add_subplot(224)
ax4.plot([1,2,3,4], [0,0,1,1], 'g-')

You get something like this: enter image description here

Second question: to redraw your plot you need to add plt.draw() after changing on a plot. But if you only want to make a set of images, just call savefig every time you need without plt.show().

Serenity
  • 35,289
  • 20
  • 120
  • 115