How to change the plotting style of the exciton weight plot in k-space

Post here any question you encounter when running the scripts of the yambo-py suite. Post here problem strictly to the python interface as problem coming from the yambo runs should go in the appropriate subforum.

Moderators: palful, amolina, mbonacci

Post Reply
Guo_BIT
Posts: 30
Joined: Tue Jun 06, 2023 2:55 am

How to change the plotting style of the exciton weight plot in k-space

Post by Guo_BIT » Thu Aug 22, 2024 7:50 am

Dear Developers,

I have successfully obtained the exciton weights using the following code.

Code: Select all

    if Kspace_Plot:
        fig = plt.figure(figsize=(10,10),dpi=300)
        ax  = fig.add_axes( [ 0, 0, 1, 1 ])
        yexc.plot_exciton_2D_ax(ax,states,mode='hexagon',limfactor= 1,scale= 1100) 
        plt.savefig('A.jpg')
However, I would like to know if the style of this image can be further modified. For example:
1. Modify the colormap of the image.
2. Obtain a colorbar and the corresponding values for each color.

Thank you. :D

Best wishes
Jingda GUo
Jingda Guo
Beijing Institute of Technology

Guo_BIT
Posts: 30
Joined: Tue Jun 06, 2023 2:55 am

Re: How to change the plotting style of the exciton weight plot in k-space

Post by Guo_BIT » Fri Aug 23, 2024 8:55 am

I'm looking forward to your reply :D
Jingda Guo
Beijing Institute of Technology

User avatar
palful
Posts: 75
Joined: Tue Jan 26, 2016 11:23 am
Location: Modena and Milan

Re: How to change the plotting style of the exciton weight plot in k-space

Post by palful » Mon Sep 02, 2024 10:47 am

Dear Jingda,

The colorbar can be added in the usual way with matplotlib but admittedly the possibility of doing so is a bit hidden.
Note that the function "plot_exciton_2D_ax" accepts all the argument (kwargs) the pyplot.scatter() function of matplotlib would accept. Also, "plot_exciton_2D_ax" returns the ax and plot objects by default.

Therefore, it is sufficient to modify your script this way:

Code: Select all

    if Kspace_Plot:
        fig = plt.figure(figsize=(10,10),dpi=300)
        ax  = fig.add_axes( [ 0, 0, 1, 1 ])
        ax, PLOT = yexc.plot_exciton_2D_ax(ax,states,mode='hexagon',limfactor= 1,scale= 1100,cmap="YOUR_CMAP_NAME") #### added cmap keywork
        plt.colorbar(PLOT) ##### plot colorbar for object PLOT
        plt.savefig('A.jpg')
Keep in mind that by adding the colorbar you change the actual plot dimensions, so you either have to increase figsize or reduce the scale parameters for the plot markers in order to have the same visualization. In general, all matplotlib plot options and "ax" methods apply to this plot and you can add them to the script just as you would for any matplotlib plot.

Cheers,
Fulvio
Dr. Fulvio Paleari
S3-CNR Institute of Nanoscience and MaX Center
Modena, Italy

Post Reply