Created
February 10, 2019 15:14
-
-
Save devforfu/c8677316dcbf69f70718a0dc4f702fc8 to your computer and use it in GitHub Desktop.
CLI with Fire
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fire | |
import matplotlib.pyplot as plt | |
from matplotlib import rcParams | |
default_style = { | |
'font.family': 'monospace', | |
'font.size': 18, | |
'figure.figsize': (8, 6) | |
} | |
class Plotter: | |
def __init__(self, style: dict=None): | |
self.style = style or default_style | |
plt.rcParams.update(self.style) | |
def scatter(self, name: str, *points): | |
n = len(points) | |
if n % 2 != 0: | |
n -= 1 | |
points = points[:n] | |
xs, ys = points[::2], points[1::2] | |
f, ax = plt.subplots(1, 1) | |
ax.scatter(xs, ys) | |
self.save(f, name) | |
def save(self, figure: plt.Figure, output: str): | |
figure.savefig(f'{output}.png', format='png') | |
if __name__ == '__main__': | |
fire.Fire(Plotter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment