Python matplotlib

From wikinotes

matplotlib is a python module that facilitates creating graphs, scatterplots, and various other data visualizations.
You may also be interested in python termplotlib for a similar interface that prints to a console.

Documentation

official docs https://matplotlib.org/3.1.1/py-modindex.html
official examples https://matplotlib.org/3.1.1/gallery/index.html

Usage

scatterplot

from matplotlib import pyplot

pyplot.title('My Title')
pyplot.xlabel('Percent')
pyplot.ylabel('Year')

data = (
  (0, 0),
  (1, 1),
  (2, 2),
  (3, 3),
)

# points
pyplot.scatter(
    [p[0] for p in data],  # x values
    [p[1] for p in data],  # y values
)

# point-labels
for p in data:
    pyplot.annotate(
        '({},{})'.format(*p), 
        xy=p,
        bbox=dict(
            boxstyle='round pad=0.5',
            fc='yellow',
        ),
    )
pyplot.show()

horizontal bargraph

from matplotlib import pyplot
import numpy

pyplot.rcdefaults()
(figure, axis) = pyplot.subplots()


# ====
# data
# ====
experience = {
    'python': 1,
    'C': 2,
    'ruby': 4,
    'rust': 2,
    'golang': 4,
}
languages = sorted(list(languages.keys()))

# =====
# graph
# =====
axis.set_title('Shoppify Languages: Times Posted')

# x-axis
axis.set_xlabel('Times Mentioned (4x postings)')

# y-axis
y_positions = numpy.arange(len(languages))
axis.set_yticks(y_positions)
axis.set_yticklabels(languages)

# bargraph
axis.barh(y_positions, [experience[l] for l in languages])

pyplot.show()