# How to plot a charge density from a CHGCAR file in Python?

I can convert a CHGCAR file on the NxNxN grid into a 3D array of shape (N,N,N) for better handling, if that helps. At the end of the day, I want plot/visualize the charge density with Python.

• My concern with this question at the moment is that it more or less asks "how do I plot 3D data with Python" which I think would be better suited for StackOverflow since its a general programming question. You should clarify what issues you are having with this that are specific to matter modeling.
– Tyberius
Jun 23 at 22:31
• I agree with you, but people in StackOverflow do not necessarily know what a CHGCAR file is, or how it looks like or why it is generated, hence might not be better equipped to answer. Jun 23 at 22:46
• Is it necessary? Almost all the published papers plot CHGCAR with vesta.
– Jack
Jun 23 at 23:14
• I think the prior two questions about format and forming the 3D array give most of what you would need in terms of the CHGCAR file. You have the density as a 3D array, the format one explains how to find the coordinate corresponding to each value. You just need to decide what type of plot you want to make and pass these to the appropriate matplotlib (or seaborn, etc) function.
– Tyberius
Jun 23 at 23:52
• @Tyberius I don't think we have to send people to SO for questions like this. We've had people ask how to find a string in a VASP output file. We've had people ask what supercomputers are available in various countries. We've had people ask whether they should try to build an HPC system with 32-128 cores. We've had people ask whether or not 2-3 laptops can be combined to make a supercomptuer. Many of these are "general" HPC questions or Hardware Recommendations questions, and there was a question about software to combine two images:Graphics.SE, SR.SE Jun 25 at 3:10