Matplotlib: different color for every point of line plot

2024/10/15 18:28:22

I'm trying to make a plot like in the following figure (source of image):figure I'm talking about the plot in the right panel even though there is some correlation between the two panels: the colorbar.

Just so you know what this is about: For every value of V, I find all N eigenvalues and eigenvectors of a NxN matrix that depends on V. The eigenvalue (this is an energy) is labeled E and is plotted in the right panel as a function of V. The value on the colorbar (let's call it IPR) is calculated from the eigenvectors and defines the color of the points in the right panel. So you see that the color and the value E are correlated which is why such a plot is pretty nice. For the physicists among you, this is a band structure as a function of some potential strength V and the IPR says something about the degree of localization of the corresponding eigenstate of the Hamiltonian.

Now my question is how I can produce such a plot in matplotlib/pyplot in a nice/efficient way. Of course one could think of a "non-pythonian" way (first calculate the data for all V, find min/max of the IPR to define the bijection between IPR and color, then go through two loops (one for all values of V, one for all N eigenvalues/-vectors at fixed V) and use some matplotlib method to get a color for every point of the plot (I assume there is such a method, even though I couldn't find one using Google)). If you take a close look you could guess that this is exactly what was done in the image. If this is the only way one of you could think of, I would be happy if anyone would let me know what said matplotlib method is. The best solution (for my purposes) would be if instead of making points, one could make N lines and still lie a color scale over it so you could still identify the bands in the plot (in the image you see vertical lines of dots but I'd rather like "vertical" lines like in a usual line plot) but I understand that this is probably not possible.

Thanks in advance!

Answer

Assuming you have your values of V, E and IPR already calculated, you can generate your plot simply by plotting E vs V using IPR as a color.

See this very nicely-detailed answer to a previous question: https://stackoverflow.com/a/17682382/1356000

https://en.xdnf.cn/q/117803.html

Related Q&A

getting template syntax error in django template

my code in view :tracks = client.get(/tracks, order=hotness, limit=4) artwork_url=[] for track in tracks:artwork_url.append(str(track.artwork_url).replace("large", "t300x300")) …

Python threading:Is it okay to read/write multiple mutually exclusive parts of a file concurrently?

I know we can guarantee correctness either by locking or using a specialized thread whose sole job is to read/write and communicate with it through queue. But this approach seems logically ok, so I wan…

Theano Cost Function, TypeError: Unknown parameter type: class numpy.ndarray

Im new to Theano, just learning it. I have a ANN in python that Im implementing in Theano as learning process. Im using Spyder.And Theano throws out an error: TypeError: Unknown parameter type: class n…

Bar plotting grouped Pandas

I have a question regarding plotting grouped DataFrame data.The data looks like:data =index taste food0 good cheese 1 bad tomato 2 worse tomato 3 worse …

Nginx+bottle+uwsgi Server returning 404 on every request

I have setup an Nginx server with following configuration:server {listen 8080;server_name localhost;location / {include uwsgi_params;uwsgi_pass unix:/tmp/uwsgi.notesapi.socket;uwsgi_param UWSGI_PYHOME …

Checking multiple for items in a for loop python

Ive written a code to tell the user that the their brackets are not balanced.I can exactly tell where my code is going wrong.Once it comes across the first situation of brackets, it does not continue t…

Can I export pandas DataFrame to Excel stripping tzinfo?

I have a timezone aware TimeSeries in pandas 0.10.1. I want to export to Excel, but the timezone prevents the date from being recognized as a date in Excel.In [40]: resultado Out[40]: fecha_hora 2013-…

Converting kwargs into variables?

How do I convert kwargs objects into local variables? I am a math teacher and I want to write a helper function where I can use JS-style template strings to write problems.I want to do something like …

Maya Python: Unbound Method due to Reload()

I have two files that import the same object tracking method from a third file. It works something like thisfile TrackingMethodclass Tracker(object):def __init__(self,nodeName=None,dag=None,obj=None):#…

How to append to a table in BigQuery using Python BigQuery API

Ive been able to append/create a table from a Pandas dataframe using the pandas-gbq package. In particular using the to_gbq method. However, When I want to check the table using the BigQuery web UI I s…