Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
teuben committed Sep 10, 2024
1 parent ffc5fc1 commit bcf532a
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions examples/simple_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,46 @@
#
# a simple matplotlib plot - testing for pipelines
#
# parent shell can optionally do:
# export MPLBACKEND=agg
# 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"
_mode = 0

import os
import sys

import numpy as np

if __name__ == "__main__":
if len(sys.argv) > 1:
_mode = int(sys.argv[1])
plotfile = 'simple_plot.png'
else:
_mode = 0
plotfile = None
if len(sys.argv) > 1:
_mode = int(sys.argv[1])
plotfile = 'simple_plot.png'
else:
_mode = 0
plotfile = None

import matplotlib
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')
import matplotlib.pyplot as plt
if 'MPLBACKEND' in os.environ:
print('$MPLBACKEND :',os.environ['MPLBACKEND'])
else:
print("no $MPLBACKEND used")
print('mpl backend :',matplotlib.get_backend())

x = np.arange(0,2,0.1)
y = np.sqrt(x)
import matplotlib.pyplot as plt
print('mpl backend :',matplotlib.get_backend())

x = np.arange(0,2,0.1)
y = np.sqrt(x)

plt.figure()
plt.plot(x,y, label="test");
plt.legend()
if plotfile == None:
plt.show()
else:
plt.savefig(plotfile)
print("Wrote",plotfile)
plt.figure()
plt.plot(x,y, label="test");
plt.legend()
if plotfile == None:
plt.show()
else:
plt.savefig(plotfile)
print("Wrote",plotfile)

0 comments on commit bcf532a

Please sign in to comment.