In [1]:
%matplotlib inline
from ggplot import *
scale_color_brewer
scale_color_brewer
provides sets of colors that are optimized for displaying data on maps. It comes from Cynthia Brewer's aptly named Color Brewer. Lucky for us, these palettes also look great on plots that aren't maps.
In [2]:
ggplot(aes(x='carat', y='price', color='clarity'), data=diamonds) +\
geom_point() +\
scale_color_brewer(type='qual')
Out[2]:
In [3]:
ggplot(aes(x='carat', y='price', color='clarity'), data=diamonds) + \
geom_point() + \
scale_color_brewer(type='seq')
Out[3]:
In [4]:
ggplot(aes(x='carat', y='price', color='clarity'), data=diamonds) + \
geom_point() + \
scale_color_brewer(type='seq', palette=4)
Out[4]:
In [5]:
ggplot(aes(x='carat', y='price', color='clarity'), data=diamonds) + \
geom_point() + \
scale_color_brewer(type='div', palette=5)
Out[5]:
scale_color_gradient
scale_color_gradient
allows you to create gradients of colors that can represent a spectrum of values. For instance, if you're displaying temperature data, you might want to have lower values be blue, hotter values be red, and middle values be somewhere in between. scale_color_gradient
will calculate the colors each point should be--even those in between colors.
In [6]:
import pandas as pd
temperature = pd.DataFrame({"celsius": range(-88, 58)})
temperature['farenheit'] = temperature.celsius*1.8 + 32
temperature['kelvin'] = temperature.celsius + 273.15
ggplot(temperature, aes(x='celsius', y='farenheit', color='kelvin')) + \
geom_point() + \
scale_color_gradient(low='blue', high='red')
Out[6]:
In [7]:
ggplot(aes(x='x', y='y', color='z'), data=diamonds.head(1000)) +\
geom_point() +\
scale_color_gradient(low='red', high='white')
Out[7]:
In [8]:
ggplot(aes(x='x', y='y', color='z'), data=diamonds.head(1000)) +\
geom_point() +\
scale_color_gradient(low='#05D9F6', high='#5011D1')
Out[8]:
In [9]:
ggplot(aes(x='x', y='y', color='z'), data=diamonds.head(1000)) +\
geom_point() +\
scale_color_gradient(low='#E1FA72', high='#F46FEE')
Out[9]:
In [10]:
my_colors = [
"#ff7f50",
"#ff8b61",
"#ff9872",
"#ffa584",
"#ffb296",
"#ffbfa7",
"#ffcbb9",
"#ffd8ca",
"#ffe5dc",
"#fff2ed"
]
ggplot(aes(x='carat', y='price', color='clarity'), data=diamonds) + \
geom_point() + \
scale_color_manual(values=my_colors)
Out[10]:
In [11]:
# https://coolors.co/app/69a2b0-659157-a1c084-edb999-e05263
ggplot(aes(x='carat', y='price', color='cut'), data=diamonds) + \
geom_point() + \
scale_color_manual(values=['#69A2B0', '#659157', '#A1C084', '#EDB999', '#E05263'])
Out[11]:
In [ ]: