complex.html


001| """Complex Parabola 3D."""
002| ####################################################################################################
003| from os import path
004| import numpy as np
005| import matplotlib.pyplot as plt
006| from matplotlib.ticker import MultipleLocator, FormatStrFormatter
007| from mpl_toolkits.mplot3d import Axes3D
008| ####################################################################################################
009| BasePath = r'C:\CJS\prj\Python\charts'
010| ImgsPath = path.join(BasePath,'img')
011| WhichView = 2
012| Filename = ('complex-%d.png' % WhichView)
013| NbrCurvesI = 11 # 3 11 41
014| print()
015| 
016| xmin,xmax =  -5.0,  +5.0
017| ymax,ymin = +25.0,  -5.0
018| zmax,zmin = +25.0, -25.0
019| Views = [
020|     (-50.0, +45.0),
021|     (-30.0, +17.0),
022|     (-90.0, +88.0),
023|     ( -3.0,  +5.0),
024| ]
025| ViewFrom = Views[WhichView-1]
026| 
027| function = lambda x,i: ((complex(x,i)**2) + complex(+4,0))
028| 
029| xx = np.linspace(xmin, xmax, 100)
030| ii = np.linspace(-1, +1, NbrCurvesI)
031| cs = [(-i,0,0) if i<0 else (0,0,i) for i in ii]
032| 
033| ####################################################################################################
034| fig = plt.figure()
035| fig.set_figwidth(8.0)
036| fig.set_figheight(6.0)
037| fig.subplots_adjust(left=0.00, bottom=0.00, right=1.00, top=1.00)
038| 
039| ax = fig.gca(projection='3d')
040| ax.set_xlabel('X Axis')
041| ax.set_ylabel('Y Axis')
042| ax.set_zlabel('Z Axis')
043| 
044| #ax.set_xlim(xmin, xmax)
045| #ax.set_ylim(ymin, ymax)
046| #ax.set_zlim(zmin, zmax)
047| 
048| ax.xaxis.set_major_locator(MultipleLocator(1.0))
049| ax.yaxis.set_major_locator(MultipleLocator(5.0))
050| ax.zaxis.set_major_locator(MultipleLocator(10.0))
051| ax.xaxis.set_major_formatter(FormatStrFormatter('%+d'))
052| ax.yaxis.set_major_formatter(FormatStrFormatter('%+d'))
053| ax.zaxis.set_major_formatter(FormatStrFormatter('%+d'))
054| 
055| ax.tick_params(direction='out')
056| ax.grid(color='#7f7fbf')
057| ax.view_init(azim=ViewFrom[0], elev=ViewFrom[1])
058| 
059| for ix,im in enumerate(2.0*ii):
060|     ns = [function(x,im) for x in xx]
061|     dy = [n.real for n in ns]
062|     dz = [n.imag for n in ns]
063|     ax.plot(xx,dy,dz, color=cs[ix], lw=2.50, alpha=0.80)
064| 
065| fn = path.join(ImgsPath, Filename)
066| fig.savefig(fn)
067| print('wrote: %s' % fn)
068| print()
069| 
070| print()
071| ####################################################################################################
072| '''eof'''
073|