spedas / pyspedas_examples

Examples of using pySPEDAS
MIT License
8 stars 4 forks source link

grid and zero line setting #28

Closed ShibotoshBiswas closed 4 months ago

ShibotoshBiswas commented 4 months ago

how to put grid and horizontal zero line (through origin) in tplot. please help !!

jameswilburlewis commented 4 months ago

You can call matplotlib directly to add a grid to your plot:

import pyspedas
import pytplot
import matplotlib.pyplot as plt

pyspedas.themis.state()
pytplot.tplot('thc_pos')
plt.grid()

To add single horizontal or vertical lines to your plot, you can use pytplot.timebar() to add a time bar or data bar as a plot option on the variable you're plotting.

Vertical line at a given time:

pytplot.timebar('2007-03-23 03:30', 'thc_pos')
pytplot.tplot('thc_pos')

For a horizontal line at a given Y value, use timebar with 'databar=True':

pytplot.timebar(10000.0, 'thc_pos', databar=True)
pytplot.tplot('thc_pos')

If you use 'return_plot_objects=True' in the call to tplot, it returns the matplotlib fig and axes objects so you can manipulate them directly with matplotlib:

fig, axes = pytplot.tplot('thc_pos', return_plot_objects=True)