Skip to content

Instantly share code, notes, and snippets.

@nicoguaro
nicoguaro / neon_example.png
Last active March 19, 2024 06:03
Plots with neon-glow in Matplotlib.
neon_example.png
@nicoguaro
nicoguaro / fit_ellip.py
Created March 16, 2017 22:07
Fit an ellipse for a point cloud
# -*- coding: utf-8 -*-
"""
Fit an ellipse for a point cloud
@author: Nicolas Guarin-Zapata
"""
from __future__ import division, print_function
import numpy as np
from numpy import sin, cos, arctan2, mean
from numpy.linalg import norm
@nicoguaro
nicoguaro / poly_fit.py
Created January 23, 2024 14:40
Polynomial fitting example in NumPy
import numpy as np
from numpy.polynomial import Polynomial
rng = np.random.default_rng()
x = np.arange(10)
y = np.arange(10) + 0.01*rng.standard_normal(10)
p_fitted = np.polynomial.Polynomial.fit(x, y, deg=1)
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
from wordcloud import WordCloud, STOPWORDS
#%%
f = open('output_file.txt', 'r', encoding="utf8")
text = f.read()
f.close()
@nicoguaro
nicoguaro / 01a_fem1d_global_sym.ipynb
Last active September 29, 2023 01:57
Notebooks con implementaciones sencillas del método de elementos finitos para la ecuación de Poisson y de Helmholtz.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nicoguaro
nicoguaro / heart.py
Created March 15, 2023 23:58
Heart surface
import numpy as np
import matplotlib.pyplot as plt
from skimage import measure
y, x, z = np.mgrid[-2:2:100j, -2:2:100j, -2:2:100j]
f = (x**2 + 9/4*y**2 + z**2 - 1)**3 - x**2 * z**3 - 9/80*y**2*z**3
verts, faces, _, _ = measure.marching_cubes(f, 0, spacing=(0.1, 0.1, 0.1))
fig = plt.figure()
@nicoguaro
nicoguaro / hull_plot.py
Created June 8, 2015 14:55
Plot the convex hull around a set of points as a shaded polygon.
# -*- coding: utf-8 -*-
"""
Plot the convex hull around a set of points as a
shaded polygon.
@author: Nicolas Guarin Zapata
@date: October 15, 2014
"""
import numpy as np
from scipy.spatial import ConvexHull
@nicoguaro
nicoguaro / plotdf.py
Last active December 16, 2022 08:29
Plot the vector field for an autonomous ODE written in the form x' = F(x,y), y' = G(x,y).
import numpy as np
from matplotlib import pyplot as plt
def plotdf(f, xran=[-5, 5], yran=[-5, 5], grid=[21, 21], color='k'):
"""
Plot the direction field for an ODE written in the form
x' = F(x,y)
y' = G(x,y)
The functions F,G are defined in the list of strings f.
@nicoguaro
nicoguaro / random_mats_eigs.py
Last active November 13, 2022 00:06
Eigenvalues for random matrices
# -*- coding: utf-8 -*-
"""
Eigenvalues for matrices with random entries with values of 1 or -1
@author: Nicolás Guarín-Zapata
@date: November 2022
"""
import numpy as np
import matplotlib.pyplot as plt
@nicoguaro
nicoguaro / mohr2d.py
Last active July 28, 2022 11:12
Scripts to plot Mohr circles.
"""
Mohr circle in 2D.
@author: Nicolás Guarín-Zapata
@date: May 2020
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams['font.family'] = 'serif'