I have a matrix H, that can take 3 directional arguments. I want to plot the eigenvalues (just think of it as function) with one set of arguments & next to it - still in the same graph - the function with another set of arguments.
This is used in physics very often i.e. when plotting band structures.
It looks like:
This is not just changing 0 to Gamma and 2pi (lattice constant =1) to X, but really doing mutlipleplots next to each other in one plot.
I have no measured data--> this is all calculated. I have a np.matrix (Hamiltonian - 8x8) that depends on 7 arguments, the only ones I change here are that of the directions.
g=Gamma, X, ... are positions (I know the directions of them.)
Each plot is generated like this:
for val in np.linspace(-np.pi/a, 0, 1000):
LG.scatter([val]*8, H(val, val , val, -15.2, -s*10.25, 19.60, -5.30))
plt.xlabel(r"$k$ in high symmetry points")
plt.xticks([-C*0.5, 0.], ["L", "$\Gamma$"])
Let me see if I'm understanding what you're after correctly.
Try something like this:
import numpy as np import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec fig = plt.figure() gs = gridspec.GridSpec(1,n, width_ratios = [width_1,...,width_n]) axes = [plt.subplot(subplot) for subplot in gs] fig.subplots_adjust(wspace=0)
Where n is the number of differing argument sets you want to be plotting and width_n is the width of each in whatever units you choose based on your normalisation.
The subplots_adjust sets the space between the subplots to 0. GridSpec gives you finer grained control over the sizes of each. The
sharey flag doesnt work with gridspec so we have to fiddle with the y-ticks manually.
You can then plot the function for each argument set, in an element of axes, with whatever ranges you want. Basically treat each element of axes as one of the graphs which you wish to concatonate together.
Using the same example as @pathoren:
def f(x, a, b, c): return a*x**2 + b*x + c fig = plt.figure() gs = gridspec.GridSpec(1, 3, width_ratios = [3, 2, 1]) axes = [plt.subplot(subplot) for subplot in gs] fig.subplots_adjust(wspace=0) x = np.linspace(0, 10, 100) y = np.linspace(2, 5 ,100) z = np.linspace(0, 2*np.pi, 100) f1 = f(x, 1, 2, 3) f2 = f(y, 3, -2, 0) f3 = f(z, -1, 2, 1) axes.plot(x, f1, label='f1') axes.set_xticks([0, 10]) axes.set_xticklabels(["L", "X"]) axes.yaxis.tick_left() axes.plot(y, f2, label='f2') axes.set_xticks() axes.set_xticklabels(["G"]) axes.yaxis.set_tick_params(size=0) plt.setp(axes.get_yticklabels(), visible=False) axes.plot(z, f3, label='f3') axes.set_xticks([2*np.pi]) axes.set_xticklabels(["Y"]) axes.yaxis.tick_right() axes.set_xlim([z,z[-1]]) plt.setp(axes.get_yticklabels(), visible=False) plt.show()
Note that the functions for changing subplot attributes like the xticks are slightly different. Using
axes.set_xlim ensures the last graph cuts off nicely.