forked from Imagelibrary/littlefs
Added plotmpl.py --github flag to match the website's foreground/background
The difference between ggplot's gray and GitHub's gray was a bit jarring. This also adds --foreground and --font-color for this sort of additional color control without needing to add a new flag for every color scheme out there.
This commit is contained in:
@@ -325,8 +325,11 @@ def main(csv_paths, output, *,
|
|||||||
dark=False,
|
dark=False,
|
||||||
ggplot=False,
|
ggplot=False,
|
||||||
xkcd=False,
|
xkcd=False,
|
||||||
|
github=False,
|
||||||
font=None,
|
font=None,
|
||||||
font_size=FONT_SIZE,
|
font_size=FONT_SIZE,
|
||||||
|
font_color=None,
|
||||||
|
foreground=None,
|
||||||
background=None):
|
background=None):
|
||||||
# guess the output format
|
# guess the output format
|
||||||
if not png and not svg:
|
if not png and not svg:
|
||||||
@@ -352,6 +355,25 @@ def main(csv_paths, output, *,
|
|||||||
if y is not None:
|
if y is not None:
|
||||||
y = [k for k, _ in y]
|
y = [k for k, _ in y]
|
||||||
|
|
||||||
|
# some shortcuts for color schemes
|
||||||
|
if github:
|
||||||
|
ggplot = True
|
||||||
|
if font_color is None:
|
||||||
|
if dark:
|
||||||
|
font_color = '#c9d1d9'
|
||||||
|
else:
|
||||||
|
font_color = '#24292f'
|
||||||
|
if foreground is None:
|
||||||
|
if dark:
|
||||||
|
foreground = '#343942'
|
||||||
|
else:
|
||||||
|
foreground = '#eff1f3'
|
||||||
|
if background is None:
|
||||||
|
if dark:
|
||||||
|
background = '#0d1117'
|
||||||
|
else:
|
||||||
|
background = '#ffffff'
|
||||||
|
|
||||||
# what colors/alphas/formats to use?
|
# what colors/alphas/formats to use?
|
||||||
if colors is not None:
|
if colors is not None:
|
||||||
colors_ = colors
|
colors_ = colors
|
||||||
@@ -369,12 +391,26 @@ def main(csv_paths, output, *,
|
|||||||
else:
|
else:
|
||||||
formats_ = FORMATS
|
formats_ = FORMATS
|
||||||
|
|
||||||
|
if font_color is not None:
|
||||||
|
font_color_ = font_color
|
||||||
|
elif dark:
|
||||||
|
font_color_ = '#ffffff'
|
||||||
|
else:
|
||||||
|
font_color_ = '#000000'
|
||||||
|
|
||||||
|
if foreground is not None:
|
||||||
|
foreground_ = foreground
|
||||||
|
elif dark:
|
||||||
|
foreground_ = '#333333'
|
||||||
|
else:
|
||||||
|
foreground_ = '#e5e5e5'
|
||||||
|
|
||||||
if background is not None:
|
if background is not None:
|
||||||
background_ = background
|
background_ = background
|
||||||
elif dark:
|
elif dark:
|
||||||
background_ = mpl.style.library['dark_background']['figure.facecolor']
|
background_ = '#000000'
|
||||||
else:
|
else:
|
||||||
background_ = plt.rcParams['figure.facecolor']
|
background_ = '#ffffff'
|
||||||
|
|
||||||
# allow escape codes in labels/titles
|
# allow escape codes in labels/titles
|
||||||
if title is not None:
|
if title is not None:
|
||||||
@@ -398,7 +434,7 @@ def main(csv_paths, output, *,
|
|||||||
if ggplot:
|
if ggplot:
|
||||||
plt.style.use('ggplot')
|
plt.style.use('ggplot')
|
||||||
plt.rc('patch', linewidth=0)
|
plt.rc('patch', linewidth=0)
|
||||||
plt.rc('axes', edgecolor=background_)
|
plt.rc('axes', facecolor=foreground_, edgecolor=background_)
|
||||||
plt.rc('grid', color=background_)
|
plt.rc('grid', color=background_)
|
||||||
# fix the the gridlines when ggplot+xkcd
|
# fix the the gridlines when ggplot+xkcd
|
||||||
if xkcd:
|
if xkcd:
|
||||||
@@ -406,28 +442,32 @@ def main(csv_paths, output, *,
|
|||||||
plt.rc('axes.spines', bottom=False, left=False)
|
plt.rc('axes.spines', bottom=False, left=False)
|
||||||
if dark:
|
if dark:
|
||||||
plt.style.use('dark_background')
|
plt.style.use('dark_background')
|
||||||
plt.rc('savefig', facecolor='auto')
|
plt.rc('savefig', facecolor='auto', edgecolor='auto')
|
||||||
# fix ggplot when dark
|
# fix ggplot when dark
|
||||||
if ggplot:
|
if ggplot:
|
||||||
plt.rc('axes',
|
plt.rc('axes',
|
||||||
facecolor='#333333',
|
facecolor=foreground_,
|
||||||
edgecolor=background_,
|
edgecolor=background_)
|
||||||
labelcolor='#aaaaaa')
|
|
||||||
plt.rc('xtick', color='#aaaaaa')
|
|
||||||
plt.rc('ytick', color='#aaaaaa')
|
|
||||||
plt.rc('grid', color=background_)
|
plt.rc('grid', color=background_)
|
||||||
|
|
||||||
if font is not None:
|
if font is not None:
|
||||||
plt.rc('font', family=font)
|
plt.rc('font', family=font)
|
||||||
plt.rc('font', size=font_size)
|
plt.rc('font', size=font_size)
|
||||||
|
plt.rc('text', color=font_color_)
|
||||||
plt.rc('figure', titlesize='medium')
|
plt.rc('figure', titlesize='medium')
|
||||||
plt.rc('axes', titlesize='medium', labelsize='small')
|
plt.rc('axes',
|
||||||
plt.rc('xtick', labelsize='small')
|
titlesize='medium',
|
||||||
plt.rc('ytick', labelsize='small')
|
labelsize='small',
|
||||||
|
labelcolor=font_color_)
|
||||||
|
if not ggplot:
|
||||||
|
plt.rc('axes', edgecolor=font_color_)
|
||||||
|
plt.rc('xtick', labelsize='small', color=font_color_)
|
||||||
|
plt.rc('ytick', labelsize='small', color=font_color_)
|
||||||
plt.rc('legend',
|
plt.rc('legend',
|
||||||
fontsize='small',
|
fontsize='small',
|
||||||
fancybox=False,
|
fancybox=False,
|
||||||
framealpha=None,
|
framealpha=None,
|
||||||
|
edgecolor=foreground_,
|
||||||
borderaxespad=0)
|
borderaxespad=0)
|
||||||
plt.rc('axes.spines', top=False, right=False)
|
plt.rc('axes.spines', top=False, right=False)
|
||||||
|
|
||||||
@@ -439,8 +479,8 @@ def main(csv_paths, output, *,
|
|||||||
fig = plt.figure(figsize=(
|
fig = plt.figure(figsize=(
|
||||||
width/plt.rcParams['figure.dpi'],
|
width/plt.rcParams['figure.dpi'],
|
||||||
height/plt.rcParams['figure.dpi']),
|
height/plt.rcParams['figure.dpi']),
|
||||||
# note we need a linewidth to keep xkcd mode happy
|
# we need a linewidth to keep xkcd mode happy
|
||||||
linewidth=8)
|
linewidth=8 if xkcd else 0)
|
||||||
ax = fig.subplots()
|
ax = fig.subplots()
|
||||||
|
|
||||||
for i, (name, dataset) in enumerate(datasets_.items()):
|
for i, (name, dataset) in enumerate(datasets_.items()):
|
||||||
@@ -844,6 +884,10 @@ if __name__ == "__main__":
|
|||||||
'--xkcd',
|
'--xkcd',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="Use the xkcd style.")
|
help="Use the xkcd style.")
|
||||||
|
parser.add_argument(
|
||||||
|
'--github',
|
||||||
|
action='store_true',
|
||||||
|
help="Use the ggplot style with GitHub colors.")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--font',
|
'--font',
|
||||||
type=lambda x: [x.strip() for x in x.split(',')],
|
type=lambda x: [x.strip() for x in x.split(',')],
|
||||||
@@ -851,6 +895,12 @@ if __name__ == "__main__":
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--font-size',
|
'--font-size',
|
||||||
help="Font size for matplotlib. Defaults to %r." % FONT_SIZE)
|
help="Font size for matplotlib. Defaults to %r." % FONT_SIZE)
|
||||||
|
parser.add_argument(
|
||||||
|
'--font-color',
|
||||||
|
help="Color for the font and other line elements.")
|
||||||
|
parser.add_argument(
|
||||||
|
'--foreground',
|
||||||
|
help="Foreground color to use.")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--background',
|
'--background',
|
||||||
help="Background color to use.")
|
help="Background color to use.")
|
||||||
|
|||||||
Reference in New Issue
Block a user