66import numpy as np
77
88class PlotStyle2D (object ):
9- Contour , PColorMesh = range (2 )
9+ Contour , Contourf , PColorMesh = range (3 )
1010
1111class PlotStyle3D (object ):
12- Contour , Wireframe , Triangle = range (3 )
12+ Contour , Contourf , Wireframe , Triangle = range (4 )
1313
1414class Plotter (object ):
1515 """
@@ -77,20 +77,24 @@ def plot(self, f, plot_style=PlotStyle2D.PColorMesh, cmap=None, *args, **kwargs)
7777
7878 if cmap is not None :
7979 if self .isstr (cmap ):
80- cmap = cm .get_cmap (cmap )
80+ kwargs ['cmap' ] = cm .get_cmap (cmap )
81+ else :
82+ kwargs ['cmap' ] = cmap
8183
8284 Z = self .compute_z (f ,X ,Y )
8385
8486 # Contour plotting
8587 if plot_style == PlotStyle2D .Contour :
86- self .ax .contourf (X , Y , Z , 1 , cmap = cmap , * args , ** kwargs )
87- if 'levels' in kwargs :
88- self .ax .contour (X , Y , Z , max (self .x_res , self .y_res ),
89- * args , ** kwargs )
88+ cs = self .ax .contour (X , Y , Z , max (self .x_res , self .y_res ),
89+ * args , ** kwargs )
90+ if 'label' in kwargs and kwargs ['label' ] is True :
91+ plt .clabel (cs , * args , ** kwargs )
92+ # Filled contour plotting
93+ elif plot_style == PlotStyle2D .Contourf :
94+ self .ax .contourf (X , Y , Z , 1 , * args , ** kwargs )
9095 # Color mesh plotting
9196 elif plot_style == PlotStyle2D .PColorMesh :
92- mesh = self .ax .pcolormesh (X , Y , Z , cmap = cmap ,
93- * args , ** kwargs )
97+ mesh = self .ax .pcolormesh (X , Y , Z , * args , ** kwargs )
9498 plt .colorbar (mesh )
9599 else :
96100 return
@@ -117,7 +121,9 @@ def plot(self, f, plot_style=PlotStyle3D.Triangle, cmap=None,
117121
118122 if cmap is not None :
119123 if self .isstr (cmap ):
120- cmap = cm .get_cmap (cmap )
124+ kwargs ['cmap' ] = cm .get_cmap (cmap )
125+ else :
126+ kwargs ['cmap' ] = cmap
121127
122128 Z = self .compute_z (f ,X ,Y )
123129
@@ -127,12 +133,13 @@ def plot(self, f, plot_style=PlotStyle3D.Triangle, cmap=None,
127133 # Triangle plotting
128134 elif plot_style == PlotStyle3D .Triangle :
129135 self .ax .plot_trisurf (X .flatten (), Y .flatten (), Z .flatten (),
130- cmap = cmap , * args , ** kwargs )
136+ * args , ** kwargs )
137+ # Filled contour plotting
138+ elif plot_style == PlotStyle3D .Contourf :
139+ self .ax .contourf (X , Y , Z , 1 , * args , ** kwargs )
131140 # Contour plotting
132141 elif plot_style == PlotStyle3D .Contour :
133- self .ax .contourf (X , Y , Z , 1 , cmap = cmap , * args , ** kwargs )
134- if 'levels' in kwargs :
135- self .ax .contour (X , Y , Z , max (self .x_res , self .y_res ),
136- * args , ** kwargs )
142+ self .ax .contour (X , Y , Z , max (self .x_res , self .y_res ),
143+ * args , ** kwargs )
137144 else :
138145 return
0 commit comments