Skip to content

Instantly share code, notes, and snippets.

@chrisraff
chrisraff / matlab_style_errorbars.py
Last active May 19, 2020 02:20
Matlab style error plotting for matplotlib pyplot
import matplotlib.pyplot as plt
import numpy as np
# matlab style errorbars
def errorbars(x, y, err, erralpha=0.2, color=None, label=None, ax=plt):
line = ax.plot(x, y, color=color, label=label)
col = line[0].get_color()
plt.fill_between(x, y-err, y+err, alpha=erralpha, color=col, zorder=-1)
# example
@chrisraff
chrisraff / hue2rgb.ino
Created February 21, 2018 05:17
Convert from hue to RGB for Arduino Neopixels
//x is in range [0, 1024]
byte hueCurve(int x) {
x += 1024/3;
x = x % 1024;
return max(255-abs(255-x*(255.0*3/1024)), 0);
}
void setHue(int led_id, int hue) {
byte r = hueCurve(hue);
byte g = hueCurve(hue+(1024*2)/3);