|
| 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