Skip to content

Commit

Permalink
update paint and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
blaylockbk committed Jun 8, 2024
1 parent 1514929 commit 4ee7339
Show file tree
Hide file tree
Showing 12 changed files with 356 additions and 951 deletions.
Binary file added docs/_static/paint/Herbie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/paint/Herbie_Colors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/paint/Herbie_Colors_lightness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/paint/Herbie_lightness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/paint/herbie_paint_landGreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/paint/herbie_paint_nws.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/paint/herbie_paint_nwsTmp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 45 additions & 11 deletions docs/user_guide/tutorial/paint/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,51 @@ Some years ago I came across a document of the NWS standard color curves, propos

![](../../../_static/paint/Land_Sequential.png)

## Colormaps with bounds
## Herbie Colormaps

In practice, these colormaps are designed with specific bounds. The classes used to define each colormap have a `kwargs` method which contains the `cmap` and `norm` objects appropriate for that colormap.
This diverging colormap uses the Herbie color palette.

![](../../../_static/paint/Herbie.png)

## Simple use
```python
from herbie import Herbie, paint
from herbie.toolbox import EasyMap, pc
import numpy as np

import matplotlib.pyplot as plt

H = Herbie("2024-01-01")
ds = H.xarray("TMP:2 m")

ax = EasyMap("50m", crs=ds.herbie.crs).BORDERS().STATES().ax
art = ax.pcolormesh(ds.longitude, ds.latitude, ds.t2m, cmap="nws.tmp", transform=pc)

plt.colorbar(art, ax=ax, orientation="horizontal", pad=0.01)
```

![](../../../_static/paint/herbie_paint_nwsTmp.png)

```python
t = H.terrain()
ax = EasyMap("50m", crs=ds.herbie.crs, add_coastlines=False).BORDERS().STATES().ax

art = ax.pcolormesh(t.longitude, t.latitude, t.orog, cmap="land.green", transform=pc)

plt.colorbar(art, ax=ax, orientation="horizontal", pad=0.01)
```

![](../../../_static/paint/herbie_paint_landGreen.png)


## Use with intended bounds

In practice, these colormaps are designed with specific bounds.

![](../../../_static/paint/herbie_paint_nws.png)


The classes used to define each colormap have a `kwargs` method which contains the `cmap` and `norm` objects appropriate for that colormap.

Your data will need to be in the expected units.

Expand All @@ -46,20 +88,12 @@ Your data will need to be in the expected units.
| `water` | Water | m |
| | | |

```python
import matplotlib.pyplot as plt

from herbie import Herbie, paint

ds = Herbie("2024-01-01").xarray("TMP:2 m")
plt.pcolormesh(ds.t2m - 273.15, **paint.NWSTemperature.kwargs2)
plt.colorbar(shrink=0.8, pad=0.01)
```

![](../../../_static/paint/NWSTemperature_kwargs2.png)

## Lightness

![](../../../_static/paint/NWS_Sequential_lightness.png)
![](../../../_static/paint/NWS_Continuous_lightness.png)
![](../../../_static/paint/Land_Sequential_lightness.png)
![](../../../_static/paint/Herbie_lightness.png)
1,120 changes: 198 additions & 922 deletions docs/user_guide/tutorial/paint/paint.ipynb

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions herbie/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
class hc:
"""Herbie Color Pallette"""

tan = "#f0ead2"
red = "#88211b"
blue = "#0c3576"
tan = "#f0ead2"
white = "#ffffff"
black = "#000000"
black = "#111111"


class ANSI:
Expand All @@ -42,7 +42,7 @@ class ANSI:
# Octal: \033
# Unicode: \u001b
# Hexadecimal: \x1B
ESC = "\x1B"
ESC = "\x1b"

# Style
bold = f"{ESC}[1m"
Expand Down Expand Up @@ -83,15 +83,14 @@ class ANSI:


def rich_herbie():
"""
Returns "▌▌Herbie" with rich colors (if rich is installed).
"""
"""Return "▌▌Herbie" with rich colors (if rich is installed)."""
return f"[on {hc.tan}][{hc.red} on {hc.white}]▌[/][{hc.blue}]▌[/][bold {hc.black}]Herbie[/][/]"


def print_rich(H):
"""
Print "rich" display console
Print "rich" display console.
TODO: How do I get the __repr__ to do this?
eh, just use my own ANSI class for text coloring.
Expand All @@ -118,7 +117,7 @@ def print_rich(H):


def HerbieLogo(white_line=False):
"""Logo of Herbie The Love Bug"""
"""Logo of Herbie The Love Bug."""
import matplotlib.patheffects as path_effects
import matplotlib.pyplot as plt

Expand Down Expand Up @@ -160,7 +159,7 @@ def HerbieLogo(white_line=False):

def HerbieLogo2(white_line=False, text_color="tan", text_stroke="black"):
"""
Herbie logo (main)
Herbie logo (main).
>>> ax = HerbieLogo2()
>>> plt.savefig('Herbie.svg', bbox_inches="tight")
Expand Down
Loading

0 comments on commit 4ee7339

Please sign in to comment.