@@ -73,23 +73,28 @@ def Render(self, Ax):
7373
7474
7575class Mesh :
76- def __init__ (self , X , Y , Scalar , ColorMap = 'viridis' , DiscretNorm = None , Label = '' ):
76+ def __init__ (self , X , Y , Scalar , ColorMap = 'viridis' , DiscretNorm = False , Label = '' ):
7777 self .X = X
7878 self .Y = Y
7979 self .Scalar = Scalar
8080 self .ColorMap = ColorMap
8181 self .Label = Label
8282
83- #norm = colors.BoundaryNorm(DiscretNorm, ColorMap) if DiscretNorm is not None else None
83+
84+ self .Norm = colors .BoundaryNorm (DiscretNorm , 200 , extend = 'both' ) if DiscretNorm is not False else None
85+
8486
8587 def Render (self , Ax ):
8688 Image = Ax .pcolormesh (self .X ,
8789 self .Y ,
8890 self .Scalar ,
89- cmap = self .ColorMap ,
90- shading = 'auto' ,
91- vmin = - np .max (np .abs (self .Scalar )),
92- vmax = + np .max (np .abs (self .Scalar )))
91+ cmap = self .ColorMap ,
92+ shading = 'auto' ,
93+ #vmin = -np.max(np.abs(self.Scalar)),
94+ #vmax = +np.max(np.abs(self.Scalar)),
95+ norm = self .Norm
96+
97+ )
9398
9499 return Image
95100
@@ -207,7 +212,7 @@ def GenerateAxis(self):
207212 self .Figure , Ax = plt .subplots (ncols = ColMax + 1 , nrows = RowMax + 1 , figsize = FigSize )
208213
209214 if not isinstance (Ax , np .ndarray ): Ax = np .asarray ([[Ax ]])
210- if Ax .shape == 1 : Ax = np .asarray ([A ])
215+ if Ax .ndim == 1 : Ax = np .asarray ([Ax ])
211216
212217 self .Figure .suptitle (self .Title )
213218
@@ -234,170 +239,6 @@ def Show(self):
234239
235240
236241
237-
238-
239-
240-
241-
242-
243-
244-
245-
246-
247- class Scene2D :
248- UnitSize = (10 , 3 )
249-
250- def __init__ (self , nCols , nRows , ColorBar = True , Projection = None , Grid = True , UnitSize = None ):
251- self .nCols = nCols
252- self .nRows = nRows
253- self .ColorBar = ColorBar
254- self .Projection = Projection
255- self .Grid = Grid
256- self .Boundaries = {'x' : [0 , 0 ], 'y' : [0 , 0 ]}
257- if UnitSize is not None : self .UnitSize = UnitSize
258-
259- self .InitScene ()
260-
261- def InitScene (self ):
262- plt .rcParams ['axes.grid' ] = self .Grid
263- plt .rcParams ['ytick.labelsize' ] = 8
264- plt .rcParams ['xtick.labelsize' ] = 8
265- plt .rcParams ["font.size" ] = 10
266- plt .rcParams ["font.family" ] = "serif"
267-
268- FigSize = [ self .UnitSize [0 ]* self .nCols , self .UnitSize [1 ]* self .nRows ]
269-
270- self .Figure , self .Axes = plt .subplots (self .nRows ,
271- self .nCols ,
272- figsize = FigSize ,
273- subplot_kw = dict (projection = self .Projection ))
274-
275- if np .size (self .Axes ) == 1 :
276- self .Axes = np .reshape (np .asarray ( [self .Axes ] ), (1 , 1 ))
277- else :
278- self .Axes = np .reshape (np .asarray ( [self .Axes ] ), (self .nRows , self .nCols ))
279-
280-
281- def AddLine (self , x , y , Col , Row , Title = None , Fill = True , Color = None , xLabel = None , yLabel = None , Legend = None ):
282- ax = self .Axes [Row , Col ]
283-
284- ax .plot (x , y , color = Color , label = Legend )
285-
286- if Title :
287- ax .set_title (Title )
288-
289- if Fill :
290- ax .fill_between (x , y .min (), y , color = Color , alpha = 0.7 )
291-
292- if xLabel :
293- ax .set_xlabel (xLabel )
294-
295- if yLabel :
296- ax .set_ylabel (yLabel )
297-
298-
299- def AddShapely (self , Col , Row , Object , Text = None ):
300- ax = self .Axes [Row , Col ]
301-
302- if isinstance (Object , Point ):
303- ax .scatter (Object .x , Object .y , linewidth = 7 )
304- self .UpdateBoundary (x = Object .x , y = Object .y )
305-
306- if isinstance (Object , (Polygon , MultiPolygon ) ):
307- Image = ax .add_patch ( PolygonPatch (Object , alpha = 0.5 ) )
308- Coord = np .array ( list (zip (* Object .exterior .coords .xy )) )
309- self .UpdateBoundary (x = Coord [:,0 ], y = Coord [:,1 ])
310-
311- if Text :
312- ax .text (Object .x , Object .y , Text )
313-
314-
315- def UpdateBoundary (self , x = None , y = None ):
316- if x is not None :
317- xMax , xMin = np .max (x ), np .min (x )
318- XBound = min (self .Boundaries ['x' ][0 ], xMin ), max (self .Boundaries ['x' ][1 ], xMax )
319- self .Boundaries ['x' ] = XBound
320-
321- if y is not None :
322- yMax , yMin = np .max (y ), np .min (y )
323- YBound = min (self .Boundaries ['y' ][0 ], yMin ), max (self .Boundaries ['y' ][1 ], yMax )
324- self .Boundaries ['y' ] = XBound
325-
326-
327- def SetAxes (self , Col , Row , Equal = None , Legend = None , xLimits = None , yLimits = None , xScale = 'linear' , yScale = 'linear' , LegendTitle = None ):
328- ax = self .Axes [Row , Col ]
329-
330- if Equal is True :
331- ax .set_aspect ('equal' )
332- if Equal is False :
333- ax .set_aspect ('auto' )
334-
335- if Legend is not None :
336- ax .legend ().set_visible (Legend )
337-
338- if xLimits == 'auto' : ax .set_xlim (self .Boundaries ['x' ])
339- if yLimits == 'auto' : ax .set_ylim (self .Boundaries ['y' ])
340-
341- if isinstance (xLimits , list ): ax .set_xlim (xLimits )
342- if isinstance (yLimits , list ): ax .set_ylim (yLimits )
343-
344- ax .set_yscale (yScale )
345- ax .set_xscale (xScale )
346-
347- if LegendTitle : ax .legend ().set_title (LegendTitle )
348-
349-
350-
351- def AddMesh (self , Col , Row , x , y , Scalar , ColorMap = 'viridis' , Title = None , xLabel = None , yLabel = None , DiscretNorm = None ):
352- ax = self .Axes [Row , Col ]
353-
354- norm = colors .BoundaryNorm (DiscretNorm , ColorMap ) if DiscretNorm is not None else None
355-
356- Image = ax .pcolormesh (x , y , Scalar , cmap = ColorMap , shading = 'auto' , vmin = - np .max (np .abs (Scalar )), vmax = + np .max (np .abs (Scalar )) )
357-
358- if Title is not None :
359- ax .set_title (Title )
360-
361- if xLabel is not None :
362- ax .set_xlabel (xLabel )
363-
364- if yLabel is not None :
365- ax .set_ylabel (yLabel )
366-
367- if self .ColorBar :
368- plt .colorbar (Image , ax = ax , location = 'bottom' )
369-
370- self .UpdateBoundary (x = x , y = y )
371- plt .tight_layout (pad = 3 )
372-
373-
374- def AddContour (self , Col , Row , x , y , Scalar , ColorMap = 'viridis' , Title = None , xLabel = None , yLabel = None , IsoLines = None ):
375- ax = self .Axes [Row , Col ]
376-
377- ax .contour (x , y , Scalar , levels = IsoLines , colors = 'black' , linewidth = .5 )
378- Image = ax .contourf (x , y , Scalar , levels = IsoLines , cmap = 'jet' , norm = colors .LogNorm () )
379-
380- if Title is not None :
381- ax .set_title (Title )
382-
383- if xLabel is not None :
384- ax .set_xlabel (xLabel )
385-
386- if yLabel is not None :
387- ax .set_ylabel (yLabel )
388-
389- if self .ColorBar :
390- plt .colorbar (Image , ax = ax , location = 'bottom' , format = "%.3f" )
391-
392- self .UpdateBoundary (x = x , y = y )
393- plt .tight_layout (pad = 3 )
394-
395-
396- def Show (self ):
397- #plt.tight_layout(pad=3)
398- plt .show ()
399-
400-
401242class Scene3D :
402243 Size = (600 , 350 )
403244 BackGround = (1 ,1 ,1 )
0 commit comments