def cplot_in_terminal(expr, *args, prec=None, logname=None, color=lambda i:
-mpmath.floor(mpmath.log(abs(i), 10))/(30 -
mpmath.floor(mpmath.log(abs(i), 10))), points=1000000, **kwargs):
"""
Run mpmath.cplot() but show in terminal if possible
"""
kwargs['color'] = color
kwargs['points'] = points
from mpmath import cplot
if prec:
mpmath.mp.dps = prec
f = lambdify(t, expr, mpmath)
try:
from iterm2_tools.images import display_image_bytes
except ImportError:
if logname:
os.makedirs('plots', exist_ok=True)
file = 'plots/%s.png' % logname
else:
file = None
cplot(f, *args, file=file, **kwargs)
else:
from io import BytesIO
b = BytesIO()
cplot(f, *args, **kwargs, file=b)
if logname:
os.makedirs('plots', exist_ok=True)
with open('plots/%s.png' % logname, 'wb') as f:
f.write(b.getvalue())
print(display_image_bytes(b.getvalue()))
评论列表
文章目录