Skip to content

Add a source for convenient plotting of tabular data#24

Open
chpolste wants to merge 2 commits intodevelopfrom
feature/tabular-source
Open

Add a source for convenient plotting of tabular data#24
chpolste wants to merge 2 commits intodevelopfrom
feature/tabular-source

Conversation

@chpolste
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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.

4 participants