#!/usr/bin/env python # coding: utf-8 # # Using Geodesics (Back-ends & Plotting) # In[1]: import numpy as np from einsteinpy.geodesic import Timelike #, Geodesic, Nulllike from einsteinpy.plotting import GeodesicPlotter, StaticGeodesicPlotter #, InteractiveGeodesicPlotter # To ensure plots show up in the documentation import plotly plotly.offline.init_notebook_mode() # ## Example 1: Exploring Schwarzschild Time-like Spiral Capture, using Python Backend and GeodesicPlotter # # ### Defining initial conditions # In[2]: # Initial Conditions position = [4., np.pi / 3, 0.] momentum = [0., 0., -1.5] a = 0. # Schwarzschild Black Hole # ### Calculating Geodesic # In[3]: geod = Timelike( metric = "Schwarzschild", metric_params = (a,), position=position, momentum=momentum, steps=15543, # As close as we can get before the integration becomes highly unstable delta=0.0005, return_cartesian=True, omega=0.01, # Small omega values lead to more stable integration suppress_warnings=True, # Uncomment to view the tolerance warning ) geod # ### Plotting using `GeodesicPlotter` # # Note that `GeodesicPlotter` automatically switches between "Static" and "Interactive" plots. Since we are in a Jupyter Notebook or Interactive Environment, it uses the "Interactive" backend. # In[4]: gpl = GeodesicPlotter() # In[5]: gpl.plot(geod, color="green", title="Geodesic Plot", aspect="auto") gpl.show() # In[6]: gpl.clear() # In Interactive mode, `clear()` must be called before drawing another plot, to avoid overlap gpl.plot2D(geod, coordinates=(1, 2), color="green", title="Top/Bottom View") # "top" / "bottom" view gpl.show() # In[7]: gpl.clear() gpl.plot2D(geod, coordinates=(1, 3), color="green", title="Face-On View") # "face-on" view gpl.show() # Each interactive plot instance (`gpl`) has a `fig` attribute that is a `plotly.graph_objs._figure.Figure` object. So, one can easily make modifications to the plots as they would to any plotly figure. For instance, we can update the title to clarify that the plot above is showing a face-on view. # In[8]: gpl.fig.layout.title = { 'text': 'Face-On View', 'x': 0.46, 'xanchor': 'center', 'y': 0.9, 'yanchor': 'top' } gpl.show() # In[9]: gpl.clear() gpl.parametric_plot(geod, colors=("red", "green", "blue")) gpl.show()