Skip to content

Commit 7879c70

Browse files
committed
basic working version of 538 theme
1 parent db69f39 commit 7879c70

File tree

3 files changed

+86
-3
lines changed

3 files changed

+86
-3
lines changed

ggplot/geoms/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from .geom_now_its_art import geom_now_its_art
1717
from .geom_path import geom_path
1818
from .geom_point import geom_point
19-
from .geom_pointrange import geom_pointrange
2019
from .geom_rect import geom_rect
2120
from .geom_smooth import geom_smooth
2221
from .geom_step import geom_step

ggplot/themes/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from .theme import theme
2+
from .theme_538 import theme_538
23
from .theme_bw import theme_bw
34
from .theme_gray import theme_gray
45
from .theme_xkcd import theme_xkcd
56
from .theme_matplotlib import theme_matplotlib
67
from .theme_seaborn import theme_seaborn
78
from .element_text import element_text
89

9-
__all__ = ["theme","theme_bw","theme_gray","theme_xkcd","theme_matplotlib",
10-
"theme_seaborn", "element_text"]
10+
__all__ = ["theme", "theme_538", "theme_bw", "theme_gray", "theme_xkcd",
11+
"theme_matplotlib", "theme_seaborn", "element_text"]
1112
__all__ = [str(u) for u in __all__]

ggplot/themes/theme_538.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
from .theme import theme
2+
3+
import matplotlib as mpl
4+
import matplotlib.pyplot as plt
5+
from numpy import isreal
6+
7+
8+
class theme_538(theme):
9+
"""
10+
Theme for 538.
11+
12+
Copied from CamDavidsonPilon's gist:
13+
https://gist.github.com/CamDavidsonPilon/5238b6499b14604367ac
14+
15+
Parameters
16+
----------
17+
"""
18+
19+
def __init__(self):
20+
super(theme_538, self).__init__(complete=True)
21+
self._rcParams["lines.linewidth"] = "2.0"
22+
self._rcParams["examples.download"] = "True"
23+
self._rcParams["patch.linewidth"] = "0.5"
24+
self._rcParams["legend.fancybox"] = "True"
25+
self._rcParams["axes.color_cycle"] = [ "#30a2da", "#fc4f30", "#e5ae38",
26+
"#6d904f", "#8b8b8b"]
27+
self._rcParams["axes.facecolor"] = "#f0f0f0"
28+
self._rcParams["axes.labelsize"] = "large"
29+
self._rcParams["axes.axisbelow"] = "True"
30+
self._rcParams["axes.grid"] = "True"
31+
self._rcParams["patch.edgecolor"] = "#f0f0f0"
32+
self._rcParams["axes.titlesize"] = "x-large"
33+
self._rcParams["svg.embed_char_paths"] = "path"
34+
self._rcParams["examples.directory"] = ""
35+
self._rcParams["figure.facecolor"] = "#f0f0f0"
36+
self._rcParams["grid.linestyle"] = "-"
37+
self._rcParams["grid.linewidth"] = "1.0"
38+
self._rcParams["grid.color"] = "#cbcbcb"
39+
self._rcParams["axes.edgecolor"] = "#f0f0f0"
40+
self._rcParams["xtick.major.size"] = "0"
41+
self._rcParams["xtick.minor.size"] = "0"
42+
self._rcParams["ytick.major.size"] = "0"
43+
self._rcParams["ytick.minor.size"] = "0"
44+
self._rcParams["axes.linewidth"] = "3.0"
45+
self._rcParams["font.size"] ="14.0"
46+
self._rcParams["lines.linewidth"] = "4"
47+
self._rcParams["lines.solid_capstyle"] = "butt"
48+
self._rcParams["savefig.edgecolor"] = "#f0f0f0"
49+
self._rcParams["savefig.facecolor"] = "#f0f0f0"
50+
self._rcParams["figure.subplot.left"] = "0.08"
51+
self._rcParams["figure.subplot.right"] = "0.95"
52+
self._rcParams["figure.subplot.bottom"] = "0.07"
53+
54+
55+
def apply_theme(self, ax):
56+
'''Styles x,y axes to appear like ggplot2
57+
Must be called after all plot and axis manipulation operations have
58+
been carried out (needs to know final tick spacing)
59+
60+
From: https://github.com/wrobstory/climatic/blob/master/climatic/stylers.py
61+
'''
62+
#Remove axis border
63+
for child in ax.get_children():
64+
if isinstance(child, mpl.spines.Spine):
65+
child.set_alpha(0)
66+
67+
#Restyle the tick lines
68+
for line in ax.get_xticklines() + ax.get_yticklines():
69+
line.set_markersize(5)
70+
line.set_markeredgewidth(1.4)
71+
72+
#Only show bottom left ticks
73+
ax.xaxis.set_ticks_position('bottom')
74+
ax.yaxis.set_ticks_position('left')
75+
76+
#Set minor grid lines
77+
ax.grid(True, 'minor', color='#F2F2F2', linestyle='-', linewidth=0.7)
78+
79+
if not isinstance(ax.xaxis.get_major_locator(), mpl.ticker.LogLocator):
80+
ax.xaxis.set_minor_locator(mpl.ticker.AutoMinorLocator(2))
81+
if not isinstance(ax.yaxis.get_major_locator(), mpl.ticker.LogLocator):
82+
ax.yaxis.set_minor_locator(mpl.ticker.AutoMinorLocator(2))
83+

0 commit comments

Comments
 (0)