Page 1 of 1

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

Posted: Thu Aug 22, 2024 7:50 am
by Guo_BIT
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

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

Posted: Fri Aug 23, 2024 8:55 am
by Guo_BIT
I'm looking forward to your reply :D

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

Posted: Mon Sep 02, 2024 10:47 am
by palful
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