Last active
May 26, 2020 15:44
-
-
Save transientlunatic/7070b66b0faa4249ba7b3266d3ba34e4 to your computer and use it in GitHub Desktop.
Some useful plotting styles
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 altair | |
def pastle(): | |
# Typography | |
font = "Lato" | |
# At Urban it's the same font for all text but it's good to keep them separate in case you want to change one later. | |
labelFont = "Source Code Pro" | |
sourceFont = "Lato" # Axes | |
axisColor = "#000000" | |
gridColor = "#4298bd" # Colors | |
main_palette = ['#8dd3c7', '#ffffb3', '#bebada', | |
'#fb8072', '#80b1d3', '#fdb462', | |
'#b3de69', '#fccde5', '#d9d9d9', | |
'#bc80bd', '#ccebc5', '#ffed6f' | |
] | |
markColor = "#fff" | |
sequential_palette = ["#cfe8f3", | |
"#a2d4ec", | |
"#73bfe2", | |
"#46abdb", | |
"#1696d2", | |
"#12719e", | |
] | |
return { | |
# width and height are configured outside the config dict because they are Chart configurations/properties not chart-elements' configurations/properties. | |
"width": 685, # from the guide | |
"height": 380, # not in the guide | |
"fill": "#ecf5f8", | |
"config": { | |
"view": { | |
"fill": "#ecf5f8", | |
"filled": True, | |
}, | |
"title": { | |
"fontSize": 18, | |
"font": font, | |
"anchor": "start", # equivalent of left-aligned. | |
"fontColor": "#000000" | |
}, | |
"axisX": { | |
"domain": True, | |
"domainColor": axisColor, | |
"domainWidth": 1, | |
"grid": True, | |
"gridColor": gridColor, | |
"gridOpacity": 0.5, | |
"labelFont": labelFont, | |
"labelFontSize": 12, | |
"labelAngle": 0, | |
"tickColor": axisColor, | |
"tickSize": 5, # default, including it just to show you can change it | |
"titleFont": font, | |
"titleFontSize": 16, | |
"titlePadding": 10, # guessing, not specified in styleguide | |
"title": "X Axis Title (units)", | |
}, | |
"axisY": { | |
"domain": True, | |
"grid": True, | |
"gridColor": gridColor, | |
"gridOpacity": 0.5, | |
"gridWidth": 1, | |
"labelFont": labelFont, | |
"labelFontSize": 12, | |
"labelAngle": 0, | |
"ticks": False, # even if you don't have a "domain" you need to turn these off. | |
"titleFont": font, | |
"titleFontSize": 16, | |
"titlePadding": 10, # guessing, not specified in styleguide | |
"title": "Y Axis Title (units)", | |
# titles are by default vertical left of axis so we need to hack this | |
# "titleAngle": 90, # horizontal | |
#"titleY": -10, # move it up | |
#"titleX": 0, # move it to the right so it aligns with the labels | |
}, | |
"range": { | |
"category": main_palette, | |
"diverging": sequential_palette, | |
}, | |
"legend": { | |
"labelFont": labelFont, | |
"labelFontSize": 12, | |
#"symbolType": "square", # just 'cause | |
"symbolSize": 100, # default | |
"titleFont": font, | |
"titleFontSize": 12, | |
"title": "", # set it to no-title by default | |
#"orient": "top-left", # so it's right next to the y-axis | |
#"offset": 0, # literally right next to the y-axis. | |
}, | |
"view": { | |
"stroke": "transparent", # altair uses gridlines to box the area where the data is visualized. This takes that off. | |
}, | |
### MARKS CONFIGURATIONS ### | |
"area": { | |
"fill": markColor, | |
}, | |
"line": { | |
"color": markColor, | |
"stroke": markColor, | |
"strokeWidth": 5, | |
}, | |
"trail": { | |
"color": markColor, | |
"stroke": markColor, | |
"strokeWidth": 0, | |
"size": 1, | |
}, | |
"path": { | |
"stroke": markColor, | |
"strokeWidth": 0.5, | |
}, | |
"point": { | |
"filled": True, | |
}, | |
"text": { | |
"font": sourceFont, | |
"color": markColor, | |
"fontSize": 11, | |
"align": "right", | |
"fontWeight": 400, | |
"size": 11, | |
}, | |
"bar": { | |
"size": 40, | |
"binSpacing": 1, | |
"continuousBandSize": 30, | |
"discreteBandSize": 30, | |
"fill": markColor, | |
"stroke": False, | |
},} | |
} | |
altair.themes.register("pastle", pastle) |
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
""" | |
This file contains some code which is useful for plotting, | |
but if you're following the tutorials you shouldn't need to worry about it. | |
""" | |
from cycler import cycler | |
blueprint = { | |
"xtick.labelsize":10, | |
"xtick.major.size": 5, | |
"xtick.minor.visible": True, | |
"xtick.color": "k", | |
"ytick.labelsize":10, | |
"ytick.major.size": 5, | |
"ytick.minor.visible": True, | |
# Lines | |
"lines.linewidth": 2, | |
"axes.prop_cycle": cycler("color", ['#FFFFFF', '#CCCCCC', '#AAAAAA']), | |
# Fonts | |
"font.monospace": ["Source code pro"], | |
"font.sans-serif": ["Source sans pro"], | |
"font.family": "monospace", | |
# Grid | |
"axes.grid": True, | |
"axes.grid.which": "both", | |
"grid.color": "#CED8F7", | |
"grid.alpha": 0.3, | |
"grid.linestyle": "-", | |
"grid.linewidth": 0.25, | |
# Plot display | |
"figure.dpi": 300, | |
# Plot facecolors | |
"axes.facecolor": "#11496f", | |
"figure.facecolor": "#FFFFFFFF" | |
} | |
pastle = { | |
"xtick.labelsize":10, | |
"xtick.major.size": 5, | |
"xtick.minor.visible": True, | |
"xtick.color": "k", | |
"ytick.labelsize":10, | |
"ytick.major.size": 5, | |
"ytick.minor.visible": True, | |
# Lines | |
"lines.linewidth": 2, | |
"axes.prop_cycle": cycler("color", ['#8dd3c7', '#ffffb3', '#bebada', | |
'#fb8072', '#80b1d3', '#fdb462', | |
'#b3de69', '#fccde5', '#d9d9d9', | |
'#bc80bd', '#ccebc5', '#ffed6f']), | |
# Fonts | |
"font.monospace": ["Source code pro"], | |
"font.sans-serif": ["Source sans pro"], | |
"font.family": "monospace", | |
# Grid | |
"grid.color": "#4298bd", | |
"grid.alpha": 0.5, | |
# Display | |
"figure.dpi": 300, | |
# Face colors | |
"axes.facecolor": "#ecf5f8", | |
"figure.facecolor": "#FFFFFFFF" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment