@complex.py
from __future__ import print_function
from os import path
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
from mpl_toolkits.mplot3d import Axes3D
ImgsPath = r'C:\CJS\prj\Python\ws\charts\imgs'
fn = 'complex.png'
function = lambda x,i: ((complex(x,i)**2) + complex(+4,0))
xmin,xmax = -5.0, +5.0
ymax,ymin = +25.0, -5.0
zmax,zmin = +25.0, -25.0
xx = np.linspace(xmin, xmax, 100)
ii = np.linspace(-1.0, +1.0, 41.0)
cs = [(-i,0,0) if i<0 else (0,0,i) for i in ii]
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
ax.set_zlabel('Z Axis')
ax.xaxis.set_major_locator(MultipleLocator(1.0))
ax.yaxis.set_major_locator(MultipleLocator(5.0))
ax.zaxis.set_major_locator(MultipleLocator(10.0))
ax.xaxis.set_major_formatter(FormatStrFormatter('%+d'))
ax.yaxis.set_major_formatter(FormatStrFormatter('%+d'))
ax.zaxis.set_major_formatter(FormatStrFormatter('%+d'))
ax.tick_params(direction='out')
ax.grid(color='#7f7fbf')
ax.view_init(azim=-45.0, elev=+17.0)
for ix,im in enumerate(4.0*ii):
ns = [function(x,im) for x in xx]
dy = [n.real for n in ns]
dz = [n.imag for n in ns]
ax.plot(xx,dy,dz, color=cs[ix], lw=1.80, alpha=0.50)
fig.set_figwidth(8.0)
fig.set_figheight(6.0)
fig.subplots_adjust(left=0.00, bottom=0.00, right=1.00, top=1.00)
fig.savefig(path.join(ImgsPath,fn))
plt.show()