z_3d.html


001| ####################################################################################################
002| from os import path
003| import numpy as np
004| import matplotlib.pyplot as plt
005| from matplotlib.ticker import MultipleLocator, FormatStrFormatter
006| ####################################################################################################
007| BasePath = r'C:\CJS\prj\Python\charts'
008| ImgsPath = path.join(BasePath,'img')
009| 
010| ##================================================================================================##
011| def do_chart_3d (data, view=1):
012|     xmin,xmax = -5.0, +5.0
013|     ymax,ymin = +5.0, -5.0
014|     zmax,zmin = +5.0, -5.0
015|     viewlist = [
016|         (  0.0, +30.0),
017|         (-45.0, +40.0),
018|         (-90.0, +30.0),
019|         (-30.0, +25.0),
020|     ]
021|     pov = viewlist[view-1]
022|     palette = [(-i,0,0) if i<0 else (0,0,i) for i in np.linspace(-1,+1,len(data))]
023| 
024|     # Create a chart...
025|     fig = plt.figure()
026|     fig.set_figwidth(8.0)
027|     fig.set_figheight(6.0)
028|     fig.subplots_adjust(left=0.00, bottom=0.00, right=1.00, top=1.00)
029| 
030|     ax = fig.gca(projection='3d')
031|     ax.set_xlabel('X Axis')
032|     ax.set_ylabel('Y Axis')
033|     ax.set_zlabel('Z Axis')
034| 
035|     ax.set_xlim(xmin, xmax)
036|     ax.set_ylim(ymin, ymax)
037|     ax.set_zlim(zmin, zmax)
038| 
039|     ax.minorticks_on()
040|     ax.xaxis.set_major_locator(MultipleLocator(1.0))
041|     ax.yaxis.set_major_locator(MultipleLocator(1.0))
042|     ax.zaxis.set_major_locator(MultipleLocator(1.0))
043|     ax.xaxis.set_major_formatter(FormatStrFormatter('%+d'))
044|     ax.yaxis.set_major_formatter(FormatStrFormatter('%+d'))
045|     ax.zaxis.set_major_formatter(FormatStrFormatter('%+d'))
046| 
047|     ax.tick_params(which='major', axis='both', direction='out')
048|     ax.tick_params(which='minor', axis='both', direction='out')
049| 
050|     ax.grid(which='major', axis='both', color='#7f7fbf', lw=1.0,ls='-', alpha=1.0, zorder=1)
051|     ax.grid(which='minor', axis='both', color='#bfbfff', lw=0.5,ls='-', alpha=1.0, zorder=0)
052| 
053|     ax.view_init(azim=pov[0], elev=pov[1])
054| 
055|     for ix,z in enumerate(data):
056|         dx = list(range(len(data)))
057|         dy = [z.real for z in data]
058|         dz = [z.imag for z in data]
059|         ax.plot(dx,dy,dz, color=palette[ix], lw=2.50, alpha=0.80)
060| 
061|     filename = path.join(BasePath,'z_3d-%d.png' % view)
062|     fig.savefig(filename)
063|     print('wrote: %s' % filename)
064|     print()
065| 
066| 
067| ####################################################################################################
068| if __name__ == '__main__':
069|     do_chart_3d([0], view=1)
070|     do_chart_3d([0], view=2)
071|     do_chart_3d([0], view=3)
072|     do_chart_3d([0], view=4)
073| ####################################################################################################
074| '''eof'''
075|