Skip to content

Instantly share code, notes, and snippets.

#### MATPLOTLIBRC FORMAT
## This is a sample matplotlib configuration file - you can find a copy
## of it on your system in
## site-packages/matplotlib/mpl-data/matplotlibrc. If you edit it
## there, please note that it will be overwritten in your next install.
## If you want to keep a permanent local copy that will not be
## overwritten, place it in the following location:
## unix/linux:
## $HOME/.config/matplotlib/matplotlibrc or
"""
===================
Anatomy of a figure
===================
This figure shows the name of several matplotlib elements composing a figure
"""
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
from scipy.special import comb, perm
import math
def plt_distribution(distribution_data_list, show=False):
fig, ax = plt.subplots()
xys, figtitle, figname = distribution_data_list
import numpy as np
import matplotlib.pyplot as plt
def area_polygons(n, l): # n: the number of edges in polygons, l: length of edges
apothem = l / (2 * np.tan(np.pi / n))
area = apothem * n * l / 2
return area
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as pli
image_data = pli.imread("lindan_smash.jpg")
I = image_data.copy()
def _mirror(image_array):
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(5, 4))
x = np.linspace(1, 5, 100)
y1 = np.ones(len(x))
y2 = np.ones(len(x)) * 2
y3 = np.ones(len(x)) * 3
y4 = np.ones(len(x)) * 4
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(3, 2, figsize=(10, 8))
x = np.linspace(1, 2 * np.pi, 100)
# y=sin(x)
i, j = 0, 0
ax[i][j].plot(x, np.sin(x), 'k-')
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(5, 4))
x = np.linspace(1, 5, 100)
y1 = np.ones(len(x))
y2 = np.ones(len(x)) * 2
y3 = np.ones(len(x)) * 3
y4 = np.ones(len(x)) * 4
import numpy as np
import matplotlib.pyplot as plt
fig, axes = plt.subplots(3, 3, sharex=True, sharey=True, figsize=(14, 10))
x = np.linspace(1, 2 * np.pi, 100)
# for i, row in enumerate(axes):
# for j, cell in enumerate(row):
# cell.plot(x,np.sin((i+1)*x))
import numpy as np
def f(x):
return x**3-3
def fdot(x):
return 3*x**2
def NewtonMethod(x0,threshold):
x_next=x0-f(x0)/fdot(x0)
diff_x=np.abs(x_next-x0)
x0=x_next