# How to plot imaginary parts of complex valued list of data separately?

I am using a user-defined function syscomplex[t1,t2,a] which calculates the complex energies of a system in a Mathematica-based software. Here:

$$t1 = 1 + cos(θ)$$
$$t2 = 1 - cos(θ)$$


and a is a parameter which takes on some specific values.I obtain complex energy values when $\theta$ is varied between [-$\pi$,$\pi$] using Bands commands in a complicated list format as can be seen here first dataset: . Now I want to plot the real and the imaginary parts of the bands versus $\theta$ separately. In this software there's a command Plotbands.

PlotBands[Im[Bands[syscomplex[t1, t2, 1], {θ, -π, π}]]]


The real part gives good plot, but the imaginary one gives error with the values of θ all zero. I understand that doing Im[] gives zero values for θ as well. So I tried solution as discussed here Listplot imaginary part of complex numbers by using the commands:

ClearAll[f]
w = Bands[syscomplex[t1, t2, 1], {θ, -π, π}]]];
f[w_] := w /. {a_, Complex[_, b_]} :> {a, b};                (1)
sm = f@w
ListLinePlot[sm, FrameLabel -> {θ, Im(E)}


which gives me a somewhat okay type list of data (see here, second dataset: )for imaginary energies versus θ. But when I plot it I do not obtain the figure I am supposed to, indicating that some values of imaginary parts are not properly taken from the list 'w' into 'sm'. Since the real part is giving me the perfect result I am wondering if there is any mistake in the commands (1). The solution as given in the previous link maybe true but my question is: can the error come from ill-formatting of the commands (1) in my case? Any help is much appreciated! You can also share your new commands which can be helpful for me. If possible give me your email so that I can provide details of my problem more clearly. Thanks a lot in advance.

Update: I now have found the problem why the imaginary parts don't give me correct plot. But I don't know how to implement it in the commands (1), so please help! If you look at the above two list data sets, you will find that the first data set (for command: w = Bands[syscomplex[t1, t2, 1], {θ, -π, π}]]]) gives real+imaginary values versus θ. Now if you carefully see these two datasets you will find that the each of the sublists in the dataset for complex values (first dataset) gives purely real values of energies for θ = [-1.51252,+1.51252] (highlighted in yellow, blue bracketed portions on the leftside denote sublist) and therefore it doesn't show the imaginary parts for θ = [-1.51252,+1.51252]. But when in the second dataset (for the command: f[w_] := w /. {a_, Complex[, b]} :> {a, b}; sm = f@w) it gives only imaginary values versus θ. In this second dataset, I find that for the same range of θ = [-1.51252,+1.51252] (highlighted in yellow, blue bracketed on the leftside portions denote sublist) in each sublist, values for the bands are incorrect. These values should have been zeroes but by mistake it takes the real parts of the values as in the first dataset. Because of this, the energy plot for imaginary is coming wrong. So, the solution lies in writing the commands (1) properly so that the energy values for the imaginary bands in the range of θ = [-1.51252,+1.51252] in each of the sublists are zeroes instead of those numbers like (-1.99625,-1.99631 etc.) Can someone please help me to correct the commands (1). I have been trying this for long, please help! Many thanks!

• t_1 means something with head 1. So, it'll match an expression like 1[foo], but no ordinary expression, like a number, will work with it. Apr 17, 2018 at 11:46
• And I don't suppose you intended it to be a pattern, anyway. Apr 17, 2018 at 11:48
• Dear John Doty, t_1 and t_2 are simply two parameters which are varied via $\theta$. Please see the highlighted update now at the bottom of the post I have added. I have found the actual problem in it. Help me how do I implement it in the commands (1). Many thanks!
– foi
Apr 17, 2018 at 14:49