Created
October 31, 2017 11:14
-
-
Save cjbayesian/3e0e2b9b91facefdfee3fec98f8b8b58 to your computer and use it in GitHub Desktop.
Plot Weierstrass' monster
This file contains 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 Weierstrass(x, reps=10): | |
res = np.zeros(x.shape[0]) | |
for i in range(reps): | |
num = x*(3**i)*np.pi | |
denom = 2.0**i | |
res = res + np.cos(num)/denom | |
return res | |
title = '$f(x) = {cos(3x\pi)}/{2} + {cos(3^2x\pi)}/{2^2} + {cos(3^3x\pi)}/{2^3} ...$' | |
delta = 0.5 | |
bg_color = 'black' | |
fg_color = 'white' | |
plt.style.use('dark_background') | |
for i,lim in enumerate(np.logspace(1,-10,200)): | |
fig = plt.figure(facecolor=bg_color, edgecolor=fg_color) | |
axes = plt.axes((0.1, 0.1, 0.8, 0.8), axisbg=bg_color) | |
axes.xaxis.set_tick_params(color=bg_color, labelcolor=bg_color) | |
axes.yaxis.set_tick_params(color=bg_color, labelcolor=bg_color) | |
x = np.linspace(-lim+delta,lim+delta,5000) | |
axes.plot(x, Weierstrass(x,41),color='red') | |
axes.set_xlim(-lim+delta,lim+delta) | |
axes.get_xaxis().get_major_formatter().set_useOffset(False) | |
axes.get_yaxis().get_major_formatter().set_useOffset(False) | |
axes.set_title(title) | |
plt.savefig('Weierstrass_{0:03d}'.format(i)) | |
plt.close() |
This file contains 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
convert -delay 10 -loop 0 Weierstrass_0* Weierstrass.gif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment