Tibor Sekera wrote: > if the data plotted are very small, I don't want to show them. I know > how to saturate the colorbar color using matplotlib.pyplot.clim But > how to 'saturate' the streamlines (i.e. plot no streamlines)?
If I understand you correctly you'd like to have something similar to the vmin/vmax parameters of kwant.plotter.map? There, one can show two different plots with the same colorbar scales. This is not possible with stock Kwant, because matplotlib's streamplot that does the actual work of tracing the stream lines does not support such functionality. (It does not fit into its logic because streamplot's stream lines are not meant to blend into the background.) Kwant's streamplot (kwant.plotter.streamplot) builds on matplotlib's by showing a background image of local flow strength and by scaling the line width according to it. Some matplotlib backends (notably PDF) have a minimum line width, and that's why Kwant's streamplot simulates thinner lines by blending their color into the background color. Thanks to this, it would actually make sense to have a vmax argument for Kwant's streamplot. I made a quick prototype (patch attached). To apply it you must install Kwant from source. Use the command "git apply vmax.patch" if you are using git and otherwise use "patch -p1 <vmax.patch". If you don't want to install Kwant from source, you can also copy the source of Kwant's streamplot to your script and apply the patch manually. Note that since I added a new keyword argument to kwant.plotter.streamplot and that argument is not known by kwant.plotter.current, you'll have to call (as explained in the docstring of kwant.plotter.current): streamplot(*interpolate_current(syst, current), vmax=my_vmax) Do let me know if you think that this would be a useful addition to Kwant. Christoph
diff --git a/kwant/plotter.py b/kwant/plotter.py index b1a2d537..7da18f73 100644 --- a/kwant/plotter.py +++ b/kwant/plotter.py @@ -2011,7 +2011,8 @@ def _linear_cmap(a, b): def streamplot(field, box, cmap=None, bgcolor=None, linecolor='k', max_linewidth=3, min_linewidth=1, density=2/9, colorbar=True, file=None, - show=True, dpi=None, fig_size=None, ax=None): + show=True, dpi=None, fig_size=None, ax=None, + vmax=None): """Draw streamlines of a flow field in Kwant style Solid colored streamlines are drawn, superimposed on a color plot of @@ -2102,6 +2103,8 @@ def streamplot(field, box, cmap=None, bgcolor=None, linecolor='k', Y = np.linspace(*box[1], num=field.shape[0]) speed = np.linalg.norm(field, axis=-1) + if vmax is None: + vmax = np.max(speed) or 1 if cmap is None: ax.set_axis_bgcolor(bgcolor) @@ -2109,9 +2112,9 @@ def streamplot(field, box, cmap=None, bgcolor=None, linecolor='k', image = ax.imshow(speed, cmap=cmap, interpolation='bicubic', extent=[e for c in box for e in c], - origin='lower') + origin='lower', vmax=vmax) - linewidth = max_linewidth / (np.max(speed) or 1) * speed + linewidth = max_linewidth / vmax * speed color = linewidth / min_linewidth linewidth[linewidth < min_linewidth] = min_linewidth color[color > 1] = 1