Skip to content

Instantly share code, notes, and snippets.

@tonysyu
tonysyu / pyproject.toml
Created November 8, 2019 18:16
Example pyproject.toml for maximum recursions in poetry
[tool.poetry]
name = "extras-export"
version = "0.1.0"
description = ""
authors = ["Tony <tsyu80@gmail.com>"]
[tool.poetry.dependencies]
python = "^3.6"
[tool.poetry.dev-dependencies]
from nose.tools import assert_equal, assert_is_not, assert_raises
def flatten_inheritance_dict(child_dict, parent_key,
expand_parent=lambda x: x):
"""Return a flattened version of dictionary that inherits from a parent.
Parameters
----------
child_dict : dict
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
RGBS = np.asarray([mcolors.hex2color(h) for h in mcolors.cnames.values()])
# Mapping from color-component name to array index
HSV_INDEX = dict(hue=0, saturation=1, value=2)
text.color: 8dd3c7
@tonysyu
tonysyu / adapt_rgb.py
Created October 18, 2012 01:40
Mock up of decorator to handle RGB images in grayscale images
import numpy as np
import matplotlib.pyplot as plt
from skimage import data, color, filter, exposure
from skimage.util import dtype
from scipy.ndimage import gaussian_filter
lab_range = (0, 100)
@tonysyu
tonysyu / mask_creator.py
Created July 11, 2012 14:25
Tool to create polygon mask in Matplotlib
"""
Interactive tool to draw mask on an image or image-like array.
Adapted from matplotlib/examples/event_handling/poly_editor.py
"""
import numpy as np
# import matplotlib as mpl
# mpl.use('tkagg')
@tonysyu
tonysyu / auto_ticker_example.py
Created January 31, 2012 01:40
Hacky attempt at automatically adjusting the number of tick labels
"""
Automatically adjust the number of ticklabels based on label width.
This is a hacky attempt at an auto tick locator and misses *many* use cases.
To test, stretch and shrink the x-axis.
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
import matplotlib.axis as maxis