Skip to content

Instantly share code, notes, and snippets.

@mdmitry1
Last active February 21, 2024 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdmitry1/8da3c0540e16b813e57960467081f1aa to your computer and use it in GitHub Desktop.
Save mdmitry1/8da3c0540e16b813e57960467081f1aa to your computer and use it in GitHub Desktop.
#!/usr/bin/python3.11
'''
https://octave.sourceforge.io/octave/function/sombrero.html
'''
from numpy import sin, sqrt, linspace,finfo, transpose
from re import search
from sys import version as python_version
#Workaround for matplotlib bug
if search('GCC UCRT', python_version): from PyQt5 import QtCore
from matplotlib import cm, pyplot as plt
N=1000
x=linspace(-8,8,num=N+1,endpoint=True).reshape(1,N+1)
x[0][N//2]=finfo(float).eps
y=x.transpose()
rs='sqrt(x**2 + y**2)'
r=eval(rs)
plt.colorbar(plt.axes(projection = '3d').plot_surface(x,y,sin(r)/r, cmap=cm.rainbow), shrink=0.5, aspect=5)
plt.setp(plt.title('sin(' + rs + ')/' + rs), color='b', backgroundcolor='lightgray')
plt.gcf().canvas.manager.set_window_title('Sombrero plot')
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment