Skip to content

Instantly share code, notes, and snippets.

@anntzer
anntzer / weave_rescale.py
Created September 11, 2013 19:14
Trying to understand how to optimize rescaling with weave
#vim: fileencoding=utf-8
import time
import timeit
import numpy as np
from scipy import weave
dtype = np.int8
@anntzer
anntzer / ffmpeg.py
Created March 22, 2016 02:05
ffmpeg.py
# Copyright 2016 Antony Lee. All rights reserved.
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
@anntzer
anntzer / wxmplot-features.md
Last active January 3, 2017 14:11
wxmplot features that could be integrated into matplotlib

New features

  • Expose artist zorder.
  • Toggle legend (via checkbox rather than click). Add recipe for legend that allows toggling artist visibility.
  • Change normalization class.

Already present

  • Change normalization bounds.
  • Change image smoothing.

Not suitable?

@anntzer
anntzer / line_time_per_edge.py
Created July 30, 2017 00:16
Time per edge in plotting lines with Matplotlib.
import time
from matplotlib import pyplot as plt
import numpy as np
ns = [10, 30, 100, 300, 1000, 3000, 10000]
all_times = []
for n in ns:
@anntzer
anntzer / cairo-manylinux.sh
Created October 9, 2017 21:25
manylinux build script for pycairo
#!/bin/bash
# Written by Antony Lee (@anntzer).
set -e
PYTHON_VERSION=36
PIP="/opt/python/cp$PYTHON_VERSION-cp${PYTHON_VERSION}m/bin/pip"
if ! [[ -e "$PIP" ]]; then
# Not in the manylinux image yet: call self from within docker.
docker run -it \
@anntzer
anntzer / test.cairoscript
Created November 3, 2017 17:05
cairo script that fails to display text on svg surface but works on pdf & ps.
%!CairoScript
<< /content //COLOR_ALPHA /width 460 /height 345 /fallback-resolution [100 100] >> surface context
1 g set-source
paint
//ALPHA [] record
dup /s6 exch def dup context
[12 0 0 12 0 0] set-font-matrix
<< /type 42 /index 0 /flags 32 /source <|!"4WsGb"-6$%*FUqEJ4bI8%tT3BHCJOCTJq"GhSa(_@96*-)uB+sIY[E.rfs+sJ/8Lr^c06psG/72?FH&J5Qd&J7m&78RM,=Vb/!!>-Ip!bVF-4k7Yr/d-=kkPK^OlLTDhRHj(;l?]%JlD^6?*^U/V3e0oXZu;SiF]=8&lNs7j+LP7*oQKV7-dHN9hhMi]Ap<Id^$!9.8S8?l/ePB3^-g4.g:m5t=s$'HeKQ:8@+SU<4"^t!T1$a]33K^XhQq4N]<3#m%3_3E6$^-JNm&ED55j?Yn9m2<0dd0caUaMBE@hIl@LCU^P!+-4aSVEc),A8>n=@3I,jYHW`!1eZCBEC!6ZO6j*]dlr[ICjEd2qR7FE#eRm@Gnj'Dq0<iHXsfOPp+2_Ro;c(OWDJFCbC'&$Fga1OLi&,V+5[i4N=84)-idJ"nY?2da]F2))*2S8C'<rH)s;5&Fi]f[7*MWqR)qjrl]KPaaONE5K]!IjL+:i9O+kkY_*;LMUI5'#uP_O<;f-c5SnB7b`uW3-fQ[kTdrkPO,endGK6Ifn>uUb@5q="21)=ppDer(Qm?"6J:\k"5pVmD8:YB4pM!"[KH;#fk8+hAp](.S/hY0hs<G_MqDb%M]%c#cEK+?T4MYd5KCW/P)'6XOJjE,Y=K#iWh]]7PAJ$MOr\e&j8e$c\U\nI0nd](>a%^!/]C/Wi`=if.39cBGcq`*P#=Z("hpiH#CO/s%t&tl!.7>:$[b+6*q2`n-f@':SUp7(F9B7hdM'dF<:YRS?[2e&
@anntzer
anntzer / fourier_demo_qt.py
Created October 19, 2019 17:43
Matplotlib's fourier_demo_wx_sgskip, but for qt.
"""
===============
Qt Fourier Demo
===============
"""
import contextlib
import sys
from matplotlib.backends.backend_qt5agg import FigureCanvas
@anntzer
anntzer / Notes
Created April 11, 2020 15:39
Improve support for dark themes in GTK3/matplotlib
Patch to have "light" icons when using a dark theme in GTK3.
Unfortunately the foreground color is reported as full white, which gives too bright icons?
@anntzer
anntzer / enum.h
Created December 8, 2020 21:25
pythonic enums with pybind11
// The ``P11X_DECLARE_ENUM`` macro and the ``p11x::bind_enums`` function
// bind enums to Python's ``enum.Enum`` or one of its subclasses
// (``enum.IntEnum``, ``enum.Flag``, ``enum.IntFlag``) -- unlike
// ``pybind11::enum_`` which uses an unrelated implementation.
//
// Use as follows:
//
// .. code-block:: c++
//
// // Define module_name.NameOfPythonEnum as an enum.Enum subclass, with
@anntzer
anntzer / fixed_width_bbox_around_text.py
Last active February 11, 2022 23:12
fixed width bbox around text
from functools import partial
import matplotlib as mpl
from matplotlib import pyplot as plt
def patched_update_bbox_position_size(text, renderer):
# Absolutely zero guarantees that the internally returned value will not
# change in future versions!
orig_get_layout = text._get_layout