- Code: Select all
#! /usr/bin/env python2.6
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
# ******* User Settings ******
image_size = 100 # <--- square, in pixels
pointer_color = 'red' # <--- can be 'black', '#000000', or rgb (000, 000, 000)
save_file_location = '/Users/username/Desktop/wind_dir.png'
wind_direction = indigo.devices[indigo_device_id].states['windDegrees']
# ****************************
wind_direction_rad = np.radians(float(wind_direction))
plt.figure(figsize=(image_size / 100.0, image_size / 100.0))
ax = plt.subplot(111, polar=True)
ax.set_theta_zero_location('N')
ax.set_theta_direction(-1)
ax.spines['polar'].set_visible(False)
ax.plot((0, wind_direction_rad), (0, 5), color=pointer_color, linewidth=3, solid_capstyle='round')
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
plt.savefig(save_file_location, transparent=True, dpi=100)
plt.close()
The resulting image is transparent (save the needle itself) and can be used regardless of whether you use the Gauge Pack or not.
I would recommend running the script from a trigger whenever the underlying data changes, and adding the image as a refreshing image URL (so that it can change when the underlying data changes without having to reload the control page.) It should work properly with any data that is constrained 0°-360°--and I believe that values greater than 360 will just start another trip around.
With the proper math, this script can be adapted for the other gauges as well. You would just need to convert your potential values across the range of degree values (something in the range of 225° - 135° I think.)
Enjoy,
Dave
[EDIT] moved to the Dave's Scripts forum.