Skip to content

Instantly share code, notes, and snippets.

@Corwinpro
Created August 20, 2017 10:42
Show Gist options
  • Save Corwinpro/fdff8a0d4c27f3d2fdd9555c1ab1f382 to your computer and use it in GitHub Desktop.
Save Corwinpro/fdff8a0d4c27f3d2fdd9555c1ab1f382 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
import math
def add_subplot_axes(ax,rect,axisbg='w'):
fig = plt.gcf()
box = ax.get_position()
width = box.width
height = box.height
inax_position = ax.transAxes.transform(rect[0:2])
transFigure = fig.transFigure.inverted()
infig_position = transFigure.transform(inax_position)
x = infig_position[0]
y = infig_position[1]
width *= rect[2]
height *= rect[3] # <= Typo was here
subax = fig.add_axes([x,y,width,height],axisbg=axisbg)
x_labelsize = subax.get_xticklabels()[0].get_size()
y_labelsize = subax.get_yticklabels()[0].get_size()
x_labelsize *= rect[2]**0.5
y_labelsize *= rect[3]**0.5
subax.xaxis.set_tick_params(labelsize=x_labelsize)
subax.yaxis.set_tick_params(labelsize=y_labelsize)
return subax
def plot(fileName, fileName2, ax, color, marker):
with open(fileName) as f:
data = f.read()
data = data.split('\n')
data = data[:-2]
x = [row.split(' ')[0] for row in data]
y = [row.split(' ')[1] for row in data]
a = 1.0# float(y[0])
x = [float(item)/a for item in x]
y = [float(item)/a for item in y]
ax.scatter(x,y,c='g', marker = marker,zorder=2, label = r'$\nabla Q/Q$')
with open(fileName2) as f:
data2 = f.read()
data2 = data2.split('\n')
data2 = data2[:-1]
x2 = [row.split(' ')[0] for row in data2]
y2 = [row.split(' ')[1] for row in data2]
a2 = 1.0#float(y2[0])
x2 = [float(item)/a2 for item in x2]
y2 = [float(item)/a2 for item in y2]
ax.scatter(x2,y2,c='r', marker = marker,zorder=2, s= 8, label = r'$\nabla Re(s) / |Re(s)|$')
for i in range(len(x)):
x1 = np.arange(-10.0, 10.0, 2)
y1 = y[i]/x[i]*x1
y3 = y2[i]/x2[i]*x1
ax.plot(x1,y1, 'k', lw=0.4)
ax.plot(x1,y3, 'k', lw=0.4)
ax.fill_between(x1, y1, y3,facecolor='lightcyan', interpolate=True)
'''
subpos = [0.58, 0.58,0.4,0.4]
subax1 = add_subplot_axes(ax,subpos)
subax1.set_xlim(-0.002, 0.006)
subax1.set_ylim(0.001, 0.006)
subax1.scatter(x2,y2,c='r', marker = marker,zorder=2)
for i in range(len(x)):
x1 = np.arange(-10.0, 10.0, 2)
y1 = y[i]/x[i]*x1
y3 = y2[i]/x2[i]*x1
subax1.plot(x1,y1, 'k', lw=0.4)
subax1.plot(x1,y3, 'k', lw=0.4)
subax1.fill_between(x1, y1, y3,facecolor='lightcyan', interpolate=True)
'''
fig = plt.figure()
ax1 = fig.add_subplot(111)
#ax1.xaxis.tick_top()
#ax1.set_xlabel(r'$Decay \ rate, kHz$')
#ax1.set_ylabel(r'$Frequency, kHz$')
ax1.set_xlim([-0.15, 0.15])
ax1.set_ylim([-0.4, 0.2])
ax1.grid(True)
plot('Q2.dat', 's2.dat', ax1, 'r', 'o')
#plot('s1.dat', ax1, 'g', 'o')
leg = ax1.legend(loc = 3)
'''
#plt.gca().invert_xaxis()
ax1.invert_xaxis()
ax2 = ax1.twiny()
plotEig('EigVals1.dat', ax2, 'r', '.')
plotEig('EigVals2.dat', ax2, 'g', '.')
ax2.set_xlim([-0.2*nuConv, 0.0])
ax2.set_ylim([0.0, 11.0*nuConv])
ax2.set_xlabel(r'$Frequency \ response$',labelpad = 10)
#new_tick_locations = np.array([-.2, -5.5, .9])
#ax2.set_xticks(new_tick_locations)
'''
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment