Matplotlib is a plotting library. It relies on some backend to actually render
the plots. The default backend is the agg
backend. This backend only renders
PNGs. On Jupyter notebooks the matplotlib backends are special as they are
rendered to the browser. Generally you will not need to explicitly set the
backend on a Jupyter notebook. This does introduce a discrepancy between code
that runs in Jupyter and code that runs as a script natively in the Python
interpreter. So you need to understand that the 2 environments are not the same
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_prime(number): | |
if number <= 0: | |
return False | |
if number == 1: | |
return True | |
elif number == 2: | |
return True | |
else: | |
for i in range(2, number): | |
if number % i == 0: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# put this in ec2 ubuntu user-data | |
mkdir /home/ubuntu/script/ | |
cat <<'EOF' >> /home/ubuntu/script/slack.sh | |
#!/bin/bash | |
ip=`/usr/bin/curl -s -w '\n' http://169.254.169.254/latest/meta-data/public-ipv4` | |
instance=`/usr/bin/curl -s -w '\n' http://169.254.169.254/latest/meta-data/instance-id` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def median(xs): | |
""" | |
When given a standard Python list of numbers, this function will | |
return the median value. There are a few cases to consider: | |
1. xs is an empty list: return None | |
2. A list with one element: returns that element | |
3. A list with an odd number of elements: Returns the middle value. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mode(xs): | |
""" | |
This returns the mode of the values in xs. xs is a standard | |
Python list with discrete values, which can be of any hashable | |
value. | |
Fo this problem, think about using a dictionary in some way. | |
What could be the keys? The values? Also remember that dictionaries | |
are UNORDERED--in other words, there is no guaranteed order. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See for tiao.io/posts/notebooks/save-matplotlib-animations-as-gifs/ more information and notes below | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib import animation, rc | |
from IPython.display import HTML, Image | |
# equivalent to rcParams['animation.html'] = 'html5' | |
rc('animation', html='html5') | |
fig, ax = plt.subplots() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.io.wavfile import write | |
# Samples per second | |
sps = 44100 | |
# Frequency / pitch of the sine wave | |
freq_hz = 440.0 | |
# Duration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from pyqtgraph.Qt import QtGui, QtCore | |
import numpy as np | |
from numpy import arange, sin, cos, pi | |
import pyqtgraph as pg | |
import sys | |
class Plot2D(): | |
def __init__(self): | |
self.traces = dict() |
Key/Command | Description |
---|---|
Tab | Auto-complete files and folder names |
Ctrl + A | Go to the beginning of the line you are currently typing on |
Ctrl + E | Go to the end of the line you are currently typing on |
Ctrl + U | Clear the line before the cursor |
Ctrl + K | Clear the line after the cursor |
Ctrl + W | Delete the word before the cursor |
Ctrl + T | Swap the last two characters before the cursor |
NewerOlder