Ejemplo n.º 1
0
 def plot_contour(self, fig, graph):
     fig.color_theme_candidate = False
     xs, ys, z_fct = self._plot_contour_init(fig, graph)
     if self.levels is not None:
         current_contour = fig.graphs[graph].graph.contour(
             xs,
             ys,
             z_fct,
             origin='lower',
             linewidths=self.linewidths,
             cmap=self.cmap,
             levels=self.levels)
     else:
         current_contour = fig.graphs[graph].graph.contour(
             xs,
             ys,
             z_fct,
             origin='lower',
             linewidths=self.linewidths,
             cmap=self.cmap)
     if fig.graphs[graph].show_cmap_legend:
         add_colorbar(current_contour, fig.graphs[graph])
     if self.clabel:
         fig.graphs[graph].graph.clabel(
             current_contour,
             inline=1,
             fmt=r'${value}$'.format(value='%1.1f'),
             fontsize=pgf_with_latex['legend.fontsize'] - 1)
     current_contour = 0
Ejemplo n.º 2
0
 def plot_contourf(self, fig, graph):
     fig.color_theme_candidate = False
     xs, ys, z_fct = self._plot_contour_init(fig, graph)
     if self.levels is not None:
         imshow = fig.graphs[graph].graph.contourf(xs,
                                                   ys,
                                                   z_fct,
                                                   cmap=self.cmap,
                                                   levels=self.levels)
     else:
         imshow = fig.graphs[graph].graph.contourf(xs,
                                                   ys,
                                                   z_fct,
                                                   cmap=self.cmap)
     if fig.graphs[graph].show_cmap_legend:
         add_colorbar(imshow, fig.graphs[graph])
Ejemplo n.º 3
0
 def _plot3d(self, fig, graph):
     fig.graphs[graph].test_graph_3d()
     x, y, z = self.x_fct, self.y_fct, self.z_fct
     theta, phi = np.meshgrid(self.theta, self.phi)
     if callable(x) :
         x = x(theta, phi)
     if callable(y) :
         y = y(theta, phi)
     if callable(z) :
         z = z(theta, phi)
     ax = fig.graphs[graph].graph
     normalize_3d(self, fig.graphs[graph], x, y, z)
     method = ax.plot_surface
     if self.use_cmap:
         C_fct_eff = self.C_fct if self.C_fct is not None else z
         if callable(self.C_fct):
             C_fct_eff = self.C_fct(theta, phi)
         cmap_low, cmap_high = self.cmap_low, self.cmap_high
         if cmap_low is None:
             cmap_low = C_fct_eff.min().min()
         if cmap_high is None:
             cmap_high = C_fct_eff.max().max()
         norm = mpl.colors.Normalize(vmin = cmap_low, vmax = cmap_high)
         facecolors = getattr(mpl.cm, self.cmap)(norm(C_fct_eff))
         surf = method(x, y, z,
                       rstride = 1,
                       cstride = 1,
                       linewidth = self.linewidth,
                       alpha = self.alpha,
                       cmap = self.cmap,
                       facecolors = facecolors
                      )
     else:
         surf = method(x, y, z,
                       rstride = 1,
                       cstride = 1,
                       linewidth = self.linewidth,
                       alpha = self.alpha,
                       color = self.color,
                       edgecolors = self.color
                      )
     if self.only_lines:
         surf.set_facecolor((1,1,1,0))
     if fig.graphs[graph].show_cmap_legend and self.use_cmap:
         m = mpl.cm.ScalarMappable(cmap = getattr(mpl.cm, self.cmap), norm = norm)
         m.set_array([])
         add_colorbar(m, fig.graphs[graph])
Ejemplo n.º 4
0
 def plot_streamplot(self,
                     fig,
                     graph,
                     start_points=None,
                     density='undef',
                     color=None,
                     linewidth=None,
                     **kwargs):
     if not isinstance(self.color, str):
         fig.color_theme_candidate = False
     elif self.color != defaults.color:
         fig.color_theme_candidate = False
     if color is None:
         color = self.color_fieldline
     if linewidth is None:
         linewidth = self.linewidth_fieldline
     if density == 'undef':
         density = 1
         if start_points is not None:
             density = len(start_points)
     if self.norm_xy:
         fig.graphs[graph].graph.set_aspect('equal', adjustable='box')
     vx, vy = self.vx_fct, self.vy_fct
     xs, ys = self.x, self.y
     if callable(self.vx_fct) and callable(self.vy_fct):
         xs, ys = np.meshgrid(xs, ys)
         vx = self.vx_fct(xs, ys)
         vy = self.vy_fct(xs, ys)
     if callable(color):
         color = color(xs, ys)
     if callable(linewidth):
         linewidth = linewidth(xs, ys)
     strm = fig.graphs[graph].graph.streamplot(xs,
                                               ys,
                                               vx,
                                               vy,
                                               start_points=start_points,
                                               density=density,
                                               color=color,
                                               linewidth=linewidth,
                                               **kwargs)
     if fig.graphs[graph].show_cmap_legend:
         add_colorbar(strm.lines, fig.graphs[graph])
Ejemplo n.º 5
0
 def plot(self, fig, graph):
     if not isinstance(self.color, str):
         fig.color_theme_candidate = False
     elif self.color != defaults.color:
         fig.color_theme_candidate = False
     elif self.use_cmap:
         fig.color_theme_candidate = False
     if self.norm_xy:
         fig.graphs[graph].graph.set_aspect('equal', adjustable='box')
     vx, vy = self.vx_fct, self.vy_fct
     xs, ys = self.x, self.y
     if callable(self.vx_fct) and callable(self.vy_fct):
         xs, ys = np.meshgrid(xs, ys)
         vx = self.vx_fct(xs, ys)
         vy = self.vy_fct(xs, ys)
     color = self.color
     if self.use_cmap:
         C_fct_eff = self.C_fct
         if callable(self.C_fct):
             C_fct_eff = self.C_fct(xs, ys).flatten()
         if self.C_fct is None:
             C_fct_eff = ((vx**2 + vy**2)**.5).flatten()
         cmap_low, cmap_high = self.cmap_low, self.cmap_high
         if cmap_low is None:
             cmap_low = C_fct_eff.min()
         if cmap_high is None:
             cmap_high = C_fct_eff.max()
         norm = mpl.colors.Normalize(vmin=cmap_low, vmax=cmap_high)
         norm.autoscale(C_fct_eff)
         color = getattr(mpl.cm, self.cmap)(norm(C_fct_eff))
     fig.graphs[graph].graph.quiver(xs,
                                    ys,
                                    vx,
                                    vy,
                                    linewidth=self.linewidth,
                                    label=self.label,
                                    color=color)
     if fig.graphs[graph].show_cmap_legend:
         m = mpl.cm.ScalarMappable(cmap=getattr(mpl.cm, self.cmap),
                                   norm=norm)
         m.set_array([])
         add_colorbar(m, fig.graphs[graph])
Ejemplo n.º 6
0
 def _plot2d(self, fig, graph):
     fig.color_theme_candidate = False
     aspect = 'auto'
     if self.norm_xy:
         fig.graphs[graph].graph.set_aspect('equal', adjustable='box')
         aspect = 'equal'
     z_fct = self.z_fct
     xs, ys = self.x, self.y
     if callable(self.z_fct):
         xs, ys = np.meshgrid(xs, ys)
         z_fct = self.z_fct(xs, ys)
     imshow = fig.graphs[graph].graph.imshow(
         z_fct,
         cmap=self.cmap,
         extent=(min(self.x), max(self.x), min(self.y), max(self.y)),
         origin='lower',
         alpha=self.alpha,
         aspect=aspect)
     if fig.graphs[graph].show_cmap_legend:
         add_colorbar(imshow, fig.graphs[graph])