objectif
Composer des graphiques avec l’API à la ggplot2.
code minimal
from plotnine import ggplot, aes, geom_point
import pandas as pd
df = pd.DataFrame({"x":[1,2,3], "y":[3,2,1]})
p = ggplot(df, aes("x","y")) + geom_point()
print("plotnine ok")
utilisation
from plotnine import ggplot, aes, geom_line
import pandas as pd
df = pd.DataFrame({"x":[1,2,3], "y":[1,4,9]})
p = ggplot(df, aes("x","y")) + geom_line()
print("line ok")
variante(s) utile(s)
from plotnine import ggplot, aes, geom_bar
import pandas as pd
df = pd.DataFrame({"cat":["a","b","c"], "v":[3,1,2]})
p = ggplot(df, aes("cat","v")) + geom_bar(stat="identity")
print("bar ok")
notes
- Export via
p.save('f.png'). Nécessite matplotlib en backend.