Load palette
pypalettes.load_palette
load_palette(name='random', reverse=False, keep_first_n=None, keep_last_n=None, keep=None, repeat=1, shuffle=False)
Load a color palette from one of the 2500+ available palettes.
You can find all valid palette names here
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Union[str, list[str]]
|
Name of the palette |
'random'
|
reverse
|
bool
|
Whether to reverse the order of the colors or not |
False
|
keep_first_n
|
Optional[int]
|
Keep only the first n colors of the palette |
None
|
keep
|
Optional[list[bool]]
|
Specify which colors to keep in the palette |
None
|
repeat
|
int
|
The number of times the palette must be present in the output. Used to access larger palettes that are repeated. |
1
|
shuffle
|
Union[bool, int]
|
Used to mix the order of colors. If an integer is supplied, it will be used as the seed. |
False
|
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of colors. |
Examples
# mkdocs: render
import seaborn as sns
from pypalettes import load_palette
palette = load_palette("Fun") # list of colors
df = sns.load_dataset("penguins")
g = sns.lmplot(
data=df,
x="bill_length_mm",
y="bill_depth_mm",
hue="species",
palette=palette,
)
- In plotnine
# mkdocs: render
import pandas as pd
from plotnine import ggplot, aes, geom_bar, theme_minimal, scale_fill_gradientn
from pypalettes import load_palette
df = pd.DataFrame({
"category": ["A", "B", "C", "D", "E"],
"value": [10, 15, 7, 12, 20]
})
colors = load_palette("Arches2", reverse=True)
(
ggplot(df, aes(x="category", y="value", fill="value"))
+ geom_bar(stat="identity")
+ scale_fill_gradientn(colors=colors)
+ theme_minimal()
)
