Tuesday, September 27, 2016

Python: Matplotlib: Dark Background Example

Noteworthy:

# "Use matplotlib style settings from a style specification."
matplotlib.style.use(style)

# "Return the length (the number of items) of an object."
len(s)

# "An instance of RcParams for handling default matplotlib values."
matplotlib.rcParams

# "Set the x axis label of the current axis."
matplotlib.pyplot.xlabel(s, *args, **kwargs)

# "Set the y axis label of the current axis."
matplotlib.pyplot.ylabel(s, *args, **kwargs)

# "Set a title of the current axes."
matplotlib.pyplot.title(s, *args, **kwargs)


Command:

$ cat testdarkbackground.py


Result:

#!/usr/local/bin/python

import numpy as np
import matplotlib.pyplot as plt

plt.style.use('dark_background')

L = 6
x = np.linspace(0, L)
ncolors = len(plt.rcParams['axes.prop_cycle'])
shift = np.linspace(0, L, ncolors, endpoint=False)
for s in shift:
    plt.plot(x, np.sin(x + s), 'o-')
plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.title('title')

plt.show()


Command:

$ python testdarkbackground.py


Graphical output: