Reputation: 17154
I have to plot the equations:
Y_axis = cos(phi) * sqrt(1 - (arctan(r)) /r )
--- for spider diagram
Here:
r = R / a_H
Y_axis = V_r - V_sys
different curves are for:
Y_axis = [0.0, 0.2, 0.4, 0.6, 0.8]
I tried :
# Imports
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0.01, 5., 100001)
ya = [0.0, 0.2, 0.4, 0.6, 0.8]
s = lambda x: np.cos(0.) * np.sqrt((1. - (1. / x) * np.arctan(x)))
plt.plot(x, s(x), 'b-', label=r'$\frac{V(R)}{V_{H}}$')
plt.show()
I have no idea how to create diagram like right figure?
The help will be highly appreciated.
Related links:
https://plot.ly/python/polar-chart/
Upvotes: 2
Views: 586
Reputation: 17154
This question is taken from :
author: Sparke and Gallagher
book: Galaxies in the Universe 2nd edition
course: Astrophysics
Borrowing ideas from Sandipan, I did it like this:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Author : Bhishan Poudel; Physics PhD Student, Ohio University
# Date : Feb 3, 2017
# Last update :
#
# Imports
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
def myplot(alpha, color='k'):
"""plot spider diagram."""
c = lambda R: 0.62 * alpha / R * (1. + R**2)**0.75
s = lambda R: np.sqrt(1. - (0.62 * alpha / R)**2 * (1. + R**2) ** 1.5)
R = np.linspace(-5., 5., 10001)
x = [i * c(i) for i in R]
x1 = [-1 * i * c(i) for i in R]
y = [i * s(i) for i in R]
label = r'$V_r - V_{sys} = $' + str(alpha) + r'$V_{max}sin(30)$'
plt.plot(x, y, label=label, color=color)
plt.plot(x1, y, label=None, color=color)
plt.legend()
def main():
"""main fn."""
alphas = [0.2, 0.4, 0.6, 0.8]
colors = sns.cubehelix_palette(4, start=0.0)
for i, alpha in enumerate(alphas):
myplot(alpha, colors[i])
# now show the plot
plt.xlim([-5., 5.])
plt.ylim([-10., 10.])
plt.xlabel(r'$x = r/a \quad cos(\phi)$')
plt.ylabel(r'$y = r/a \quad sin(\phi)$')
plt.legend(frameon=False, loc=1)
plt.title(r'Fig. Spider diagram for rotational curve for Plummer model')
# plt.savefig('fig_5_19a.pdf', bbox_inches='tight')
plt.show()
if __name__ == '__main__':
main()
The resultant image is:
UPDATE
The closest figure I got it:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Author : Bhishan Poudel; Physics PhD Student, Ohio University
# Date : Feb 3, 2017
# Last update :
#
# Imports
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
def myplot(alpha):
"""plot spider diagram."""
R = np.linspace(-5., 5., 1001)
c = lambda R: 0.62 * alpha / R * (1. + R**2)**0.75
s = lambda R: np.sqrt(1. - (0.62 * alpha / R)**2 * (1. + R**2) ** 1.5)
x = [i * c(i) for i in R]
x1 = [-1 * i * c(i) for i in R]
y = [i * s(i) for i in R]
plt.text(np.nanmax(x)+0.1, np.nanmax(y), alpha)
plt.plot(x, y, 'k-')
plt.plot(x1, y, 'k:')
# add circle
circle1=plt.Circle((0,0),5,color='k', fill=False, ls='--')
plt.gcf().gca().add_artist(circle1)
def main():
"""main fn."""
alphas = [0.2, 0.4, 0.6, 0.8]
for i, alpha in enumerate(alphas):
myplot(alpha)
# now show the plot
plt.xlim([-10., 10.])
plt.ylim([-10., 10.])
plt.legend(frameon=False)
plt.grid(False)
plt.axis('off')
plt.savefig('hello.png')
plt.show()
if __name__ == '__main__':
main()
Upvotes: 2
Reputation: 23099
You can try this to get a somewhat similar plot (play with the parameters to modify to resemble the one desired). What you need is contour plot
since you have a bivariate function y=f(x,phi)
.
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-5., 5., 1001)
phi = np.linspace(-1., 1., 1001)
X, Phi = np.meshgrid(x, phi)
Y = np.cos(Phi) * np.sqrt((1. - (1. / X) * np.arctan(X)))
plt.contour(X, Phi, Y)
plt.show()
Upvotes: 2