Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/astroumd/lmtoy
Browse files Browse the repository at this point in the history
  • Loading branch information
teuben committed Sep 10, 2024
2 parents 95e6e21 + adb4294 commit 0db8eb6
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/README_sequoia.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Version: 30-jul-2024
SRC_OBSNUM.wt3.fits weight map v3 - RMS in line free region

SRC_OBSNUM.wtn.fits ...coverage map (normalized) *BAD BEAM*
SRC_OBSNUM.wtr.fits ratio of wt3/wt3
SRC_OBSNUM.wtr.fits ratio of wt3/wt2
SRC_OBSNUM.wtr3.fits ...
SRC_OBSNUM.wtr4.fits RMS expected from radiometer equation (weighted average of Tsys/sqrt(df.dt))

Expand Down
87 changes: 68 additions & 19 deletions examples/simple_plot.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,94 @@
#! /usr/bin/env python
#
# a simple matplotlib plot - testing for pipelines
# a simple matplotlib plot: testing for MPL capabilities
#
# setting the backend:
# 1. rcParams["backend"] parameter in your matplotlibrc file
# 2. The MPLBACKEND environment variable
# 3. The function matplotlib.use()
#
_version = "3-sep-2023"
_version = "10-sep-2023"

_help = """Usage: simple_plot.py [options]
-p --plotfile PLOTFILE Plot filename, extension is important. Optional.
It none given, output should appear on screen.
-b --backend BACKEND Optional MPLBACKEND to use
-s --show Show available backends
-d --debug More debugging output?
-h --help This help
-v --version Script version
This script allows you to easily test for matplotlib's
capabilities in terms of picking interactive plotting
vs. creating a plotfile, and selecting a backend
if the default is not sufficient.
By default the script should bring up an interactive plot
and report in the title what backend was used.
One can also set a default backend via an environment variable
export MPLBACKEND=agg
or your matplotlibrc file (location varies per platform).
Use --debug to see which one you should use.
"""

import os
import sys
import numpy as np
from docopt import docopt

if len(sys.argv) > 1:
_mode = int(sys.argv[1])
plotfile = 'simple_plot.png'
else:
_mode = 0
plotfile = None
# 1. Grab the command line arguments
av = docopt(_help, options_first=True, version=_version)
_debug = av['--debug']
if _debug:
print(av)

plotfile = av['--plotfile']
backend = av['--backend']
_mode = -1


# 2. MATPLOTLIB settings
import matplotlib
if 'MPLBACKEND' in os.environ:
print('$MPLBACKEND :',os.environ['MPLBACKEND'])
matplotlib.use(os.environ['MPLBACKEND']) # isn't this redundant?
else:
print("no $MPLBACKEND used")
if _mode == 0:
matplotlib.use('qt5agg')
else:
matplotlib.use('agg')

if av['--show']:
gui_env = [i for i in matplotlib.rcsetup.interactive_bk]
non_gui_backends = matplotlib.rcsetup.non_interactive_bk
print ("Non Gui backends are:", non_gui_backends)
print ("Gui backends I will test for", gui_env)
sys.exit(0)

if plotfile is not None:
matplotlib.use('agg') # use common plotfile capable backend
if backend is not None:
matplotlib.use(backend) # unless forced otherwise with --backend

import matplotlib.pyplot as plt
print('mpl backend :',matplotlib.get_backend())

if _debug:
print("Your matplotlibrc file:",matplotlib.matplotlib_fname())
if 'MPLBACKEND' in os.environ:
print('$MPLBACKEND :',os.environ['MPLBACKEND'])
else:
print("no $MPLBACKEND used")

backend = matplotlib.get_backend()
if _debug:
print('mpl backend :',backend)


# 3. Compute and plot
x = np.arange(0,2,0.1)
y = np.sqrt(x)

plt.figure()
plt.plot(x,y, label="test");
plt.legend()
msg = f"plotfile={plotfile} mode={_mode} backend={backend}"
plt.title(msg)

if plotfile == None:
plt.show()
else:
Expand Down

0 comments on commit 0db8eb6

Please sign in to comment.