Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a source for convenient plotting of tabular data #24

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

chpolste
Copy link
Member

A basic source to simplify plotting of DataFrame(-like) objects:

import numpy as np
import pandas as pd
import earthkit.plots
import earthkit.plots.quickplot as qplt

Uses the x, y and z arguments to access columns, e.g.,

df = pd.DataFrame({"foo": [9, 16, 25], "bar": [3, 4, 5]})
qplt.line(df, x="bar", y="foo")

and falls back on the index for the x coordinate (if an index exists).

Also works with spatial data stored in a table, e.g.,

lat, lon = np.meshgrid(np.linspace(80, 20), np.linspace(-50, 50))
values = 10*np.sin(np.deg2rad(lon))*np.cos(np.deg2rad(9*lat))

df = pd.DataFrame({
    "lat": lat.flatten(),
    "lon": lon.flatten(),
    "values": values.flatten()
})

qplt.contourf(df, z="values")

or

subplot = earthkit.plots.Map()
subplot.contourf(df, z="values")
subplot.coastlines()

though it's not playing nice with quickmap as there is no datetime method on TabularSource.

I would like to automatically generate labels (for a line or the axes) based on the column names like pandas does with its built-in plotting routines but haven't been able to figure out how to do that yet.

@FussyDuck
Copy link

FussyDuck commented Oct 30, 2024

CLA assistant check
All committers have signed the CLA.

@chpolste chpolste added the enhancement New feature or request label Oct 30, 2024
@JamesVarndell
Copy link
Collaborator

Hi @chpolste, this looks really great! I'm currently in the process of overhauling the earthkit-plots source objects, which should be released next week. Once that's out, we can tweak this tabular source and merge it in - should be a great addition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants