Skip to content

Instantly share code, notes, and snippets.

View hugke729's full-sized avatar

Ken Hughes hugke729

View GitHub Profile
@hugke729
hugke729 / elaborate_matplotlib_animations.py
Last active February 28, 2022 05:42
Quiver, 3D contour, polar, scatter, and fill animations with Matplotlib
# Example animations using matplotlib's FuncAnimation
# Ken Hughes. August 2019
# For more detail, see
#https://brushingupscience.com/2019/08/01/elaborate-matplotlib-animations/
# Examples include
# - quiver plot with variable positions and directions
# - 3D contour plot
# - line plot on a polar projection
@hugke729
hugke729 / autokey_alternative.md
Created May 28, 2019 21:40
An alternative way to input unicode characters with Autokey

An alternative way to input unicode characters with Autokey

The post Add any symbol without leaving the keyboard explains how to input unicode characters easily on Linux. However, the instructions given may not always work or you may be stuck with Autokey version 2, which doesn't play nice with unicode. What follows is a brief description of a work-around.

First, create a file called MyCopy.py containing the following

import sys
reload(sys)
sys.setdefaultencoding('utf8')
@hugke729
hugke729 / Sublime and Matlab (Windows).md
Last active July 30, 2021 14:31
Use Sublime Text and Matlab together in a REPL-like fashion

Running an m-file or selected code from Sublime in Matlab's command window

A supplement to the Brushing Up Science post: Invest in a good text editor

I use both Matlab and Sublime Text. Although I edit m-files in Sublime, when I run the file or evaluate lines, I do so in Matlab. Detailed below is how I achieve this in such a way that if I want to run the file or evaluate the selected lines, I simply press Shift + Enter.

This example works for Windows using AutoHotKey. For Linux instructions, click here

Step 1: Autokey code

@hugke729
hugke729 / Sublime and Python (Windows).md
Last active August 7, 2023 15:03
Use Sublime and Spyder together in a REPL-like fashion

Running a Python script or selected code from Sublime in Spyder's IPython console

A supplement to the Brushing Up Science post: Invest in a good text editor

I like to use both Python and Sublime Text. But I also like Spyder as a Python IDE. Therefore, although I edit in Sublime, to run scripts or evaluate lines of code in a REPL-like fashion, I do so via Spyder. Detailed below is how I achieve this in such a way that if I want to run the file or evaluate the selected lines, I simply press Shift + Enter.

This example works for Windows using AutoHotKey. For Linux instructions, click here.

Step 1: AutoHotKey code

@hugke729
hugke729 / Sublime and Python (Linux).md
Last active January 25, 2023 15:53
Use Sublime and Spyder together in a REPL-like fashion

Running a Python script or selected code from Sublime in Spyder's IPython console

A supplement to the Brushing Up Science post: Invest in a good text editor

I like to use both Python and Sublime Text. But I also like Spyder as a Python IDE. Therefore, although I edit in Sublime, to run scripts or evaluate lines of code in a REPL-like fashion, I do so via Spyder. Detailed below is how I achieve this in such a way that if I want to run the file or evaluate the selected lines, I simply press Shift + Enter.

This example works for Linux using Autokey. For Windows instructions, click here.

Step 1: Autokey code

@hugke729
hugke729 / Sublime and Matlab (Linux).md
Last active June 29, 2023 15:46
Use Sublime Text and Matlab together in a REPL-like fashion

Running an m-file or selected code from Sublime in Matlab's command window

A supplement to the Brushing Up Science post: Invest in a good text editor

I use both Matlab and Sublime Text. Although I edit m-files in Sublime, when I run the file or evaluate lines, I do so in Matlab. Detailed below is how I achieve this in such a way that if I want to run the file or evaluate the selected lines, I simply press Shift + Enter.

This example works for Linux using Autokey. For Windows instructions, click here

Step 1: Autokey code

@hugke729
hugke729 / rasterize_and_save.py
Last active December 3, 2023 02:55
Simplify export of matplotlib figures when both raster and vector components are desired in output
# A function to rasterize components of a matplotlib figure while keeping
# axes, labels, etc as vector components
# https://brushingupscience.wordpress.com/2017/05/09/vector-and-raster-in-one-with-matplotlib/
from inspect import getmembers, isclass
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
def rasterize_and_save(fname, rasterize_list=None, fig=None, dpi=None,
# Example animations using matplotlib's FuncAnimation
# Ken Hughes. 18 June 2016.
# For more detail, see
# https://brushingupscience.wordpress.com/2016/06/21/matplotlib-animations-the-easy-way/
# Examples include
# - line plot
# - pcolor plot
# - scatter plot
\documentclass{beamer}
\definecolor{blue}{rgb}{0,0,0.8}
\usetheme{Hannover}
\usecolortheme{beaver}
\setbeamercovered{transparent=30}
\setbeamercolor{section in sidebar}{fg=blue}
\setbeamercolor{subsection in sidebar}{fg=blue}
\setbeamercolor{title in sidebar}{fg=blue}
\setbeamercolor{title}{fg=blue}
#SingleInstance Force
; AutoHotKey script to allow for easy input of various unicode characters often used in science.
; Written by Ken Hughes Jan 2015
; Tested with Windows 7 and 10
; Example:
; Type in /Delta and the script will automatically replace with Δ
; For best results, save this script into your startup folder which will be something like
; C:\Users\<USERNAME>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
; Autohotkey allows simpler ways to convert text to other text, but for unicode characters to work with Inkscape as well, they appear to need the function svc below.