Fixing min and max values of colormap using kwant.plot
Dear All, I am using the kwant.plot and kwant.wavefunction functions to plot the wavefunction's sqaured amplitude on the system. For my work, I need to compare such plots on two different systems. It is tough to compare the values as the max and min is not defined on the colorbar. For example, if system 1 has a max value of 0.9 it will be shown as yellow. However, if system 2 has a max value of 2.4 it will also be shown as yellow because the max value gets automatically assigned to the top of the colorbar (inferno in this case). Would it be possible to assign the max of the colorbar to a fixed number, say 5, for all plots. That way the value 5 will be yellow and 2.4 could be orange while 0.9 could be blue - leading to easier comparison between plots of seen side by side. Any help would be greatly appreciated. Thanks and best regards, Shivang Agarwal -- *Shivang Agarwal* Senior Undergraduate Coordinator - Academic Discussion Hours Discipline of Electrical Engineering IIT Gandhinagar Contact: +91-9869321451
Dear Shivang, Just use the options you have in matplotlib. You can, for example, write help(kwant.plotter.map) you get: Help on function map in module kwant.plotter: map(sys, value, colorbar=True, cmap=None, vmin=None, vmax=None, a=None, method='nearest', oversampling=3, num_lead_cells=0, file=None, show=True, dpi=None, fig_size=None, ax=None, pos_transform=None, background='#e0e0e0') Show interpolated map of a function defined for the sites of a system. Create a pixmap representation of a function of the sites of a system by calling `~kwant.plotter.mask_interpolate` and show this pixmap using matplotlib. Parameters ---------- sys : kwant.system.FiniteSystem or kwant.builder.Builder The system for whose sites `value` is to be plotted. value : function or list Function which takes a site and returns a value if the system is a builder, or a list of function values for each system site of the finalized system. colorbar : bool, optional Whether to show a color bar if numerical data has to be plotted. Defaults to `True`. If `ax` is provided, the colorbar is never plotted. cmap : ``matplotlib`` color map or `None` The color map used for sites and optionally hoppings, if `None`, ``matplotlib`` default is used. vmin : float, optional The lower saturation limit for the colormap; values returned by `value` which are smaller than this will saturate vmax : float, optional The upper saturation limit for the colormap; valued returned by `value` which are larger than this will saturate I hope this helps, Adel On Mon, Nov 19, 2018 at 12:42 PM Shivang Agarwal < shivang.agarwal@iitgn.ac.in> wrote:
Dear All,
I am using the kwant.plot and kwant.wavefunction functions to plot the wavefunction's sqaured amplitude on the system. For my work, I need to compare such plots on two different systems. It is tough to compare the values as the max and min is not defined on the colorbar. For example, if system 1 has a max value of 0.9 it will be shown as yellow. However, if system 2 has a max value of 2.4 it will also be shown as yellow because the max value gets automatically assigned to the top of the colorbar (inferno in this case).
Would it be possible to assign the max of the colorbar to a fixed number, say 5, for all plots. That way the value 5 will be yellow and 2.4 could be orange while 0.9 could be blue - leading to easier comparison between plots of seen side by side.
Any help would be greatly appreciated.
Thanks and best regards, Shivang Agarwal
-- *Shivang Agarwal* Senior Undergraduate Coordinator - Academic Discussion Hours Discipline of Electrical Engineering IIT Gandhinagar
Contact: +91-9869321451
-- Abbout Adel
Hi Adel, Thank you for the quick response. When I try *kwant.plotter.map(sys, value, vmin=0, vmax=2) *I get the following error: ValueError: Only 2D systems can be plotted this way. My system is a 3D system. I would be glad if you could help me out in this regard. Best regards, Shivang Agarwal On Mon, Nov 19, 2018 at 6:57 PM Abbout Adel <abbout.adel@gmail.com> wrote:
Dear Shivang, Just use the options you have in matplotlib. You can, for example, write help(kwant.plotter.map) you get:
Help on function map in module kwant.plotter:
map(sys, value, colorbar=True, cmap=None, vmin=None, vmax=None, a=None, method='nearest', oversampling=3, num_lead_cells=0, file=None, show=True, dpi=None, fig_size=None, ax=None, pos_transform=None, background='#e0e0e0') Show interpolated map of a function defined for the sites of a system.
Create a pixmap representation of a function of the sites of a system by calling `~kwant.plotter.mask_interpolate` and show this pixmap using matplotlib.
Parameters ---------- sys : kwant.system.FiniteSystem or kwant.builder.Builder The system for whose sites `value` is to be plotted. value : function or list Function which takes a site and returns a value if the system is a builder, or a list of function values for each system site of the finalized system. colorbar : bool, optional Whether to show a color bar if numerical data has to be plotted. Defaults to `True`. If `ax` is provided, the colorbar is never plotted. cmap : ``matplotlib`` color map or `None` The color map used for sites and optionally hoppings, if `None`, ``matplotlib`` default is used. vmin : float, optional The lower saturation limit for the colormap; values returned by `value` which are smaller than this will saturate vmax : float, optional The upper saturation limit for the colormap; valued returned by `value` which are larger than this will saturate
I hope this helps,
Adel
On Mon, Nov 19, 2018 at 12:42 PM Shivang Agarwal < shivang.agarwal@iitgn.ac.in> wrote:
Dear All,
I am using the kwant.plot and kwant.wavefunction functions to plot the wavefunction's sqaured amplitude on the system. For my work, I need to compare such plots on two different systems. It is tough to compare the values as the max and min is not defined on the colorbar. For example, if system 1 has a max value of 0.9 it will be shown as yellow. However, if system 2 has a max value of 2.4 it will also be shown as yellow because the max value gets automatically assigned to the top of the colorbar (inferno in this case).
Would it be possible to assign the max of the colorbar to a fixed number, say 5, for all plots. That way the value 5 will be yellow and 2.4 could be orange while 0.9 could be blue - leading to easier comparison between plots of seen side by side.
Any help would be greatly appreciated.
Thanks and best regards, Shivang Agarwal
-- *Shivang Agarwal* Senior Undergraduate Coordinator - Academic Discussion Hours Discipline of Electrical Engineering IIT Gandhinagar
Contact: +91-9869321451
-- Abbout Adel
-- *Shivang Agarwal* Senior Undergraduate Coordinator - Academic Discussion Hours Discipline of Electrical Engineering IIT Gandhinagar Contact: +91-9869321451
Hi,
Thank you for the quick response. When I try /kwant.plotter.map(sys, value, vmin=0, vmax=2) /I get the following error: ValueError: Only 2D systems can be plotted this way. My system is a 3D system. I would be glad if you could help me out in this regard.
As the error message says, 'kwant.plotter.map' doesn't work for 3D systems. Matplotlib does not have very good support for 3D plots in any case, and it's not clear that there's a general "best way" of plotting a 3D scalar field. Probably your best bet will be to reduce the dimensionality of what you're trying to plot. Failing that, you could try using 'kwant.plotter.interpolate_density' (available in the current development version of Kwant and in the soon-to-be-released Kwant 1.4) with the 'ipyvolume' [1] package; something like: import ipyvolume ... field, box = kwant.plotter.interpolate_density(syst, some_density) field = field.squeeze() # ipyvolume requires a rank-3 array ipyvolume.quickvolshow(field) Note that the above code is incomplete and untested; it's just to show how you could glue the relevant pieces together. Happy Kwanting, Joe [1]: https://ipyvolume.readthedocs.io/en/latest/
Hello Joseph, Thanks a lot for the information. I will try this method and see what I can do with it. Best regards, Shivang Agarwal On Mon 19 Nov, 2018, 7:35 PM Joseph Weston <joseph.weston08@gmail.com wrote:
Hi,
Thank you for the quick response. When I try *kwant.plotter.map(sys, value, vmin=0, vmax=2) *I get the following error:
ValueError: Only 2D systems can be plotted this way.
My system is a 3D system. I would be glad if you could help me out in this regard.
As the error message says, 'kwant.plotter.map' doesn't work for 3D systems. Matplotlib does not have very good support for 3D plots in any case, and it's not clear that there's a general "best way" of plotting a 3D scalar field.
Probably your best bet will be to reduce the dimensionality of what you're trying to plot.
Failing that, you could try using 'kwant.plotter.interpolate_density' (available in the current development version of Kwant and in the soon-to-be-released Kwant 1.4) with the 'ipyvolume' [1] package; something like:
import ipyvolume
...
field, box = kwant.plotter.interpolate_density(syst, some_density)
field = field.squeeze() # ipyvolume requires a rank-3 array
ipyvolume.quickvolshow(field)
Note that the above code is incomplete and untested; it's just to show how you could glue the relevant pieces together.
Happy Kwanting,
Joe
participants (3)
-
Abbout Adel -
Joseph Weston -
Shivang Agarwal