Use .map and .map_dataframe with Seaborn object interface #3655
-
Hi, I am cross-posting here from Stackoverflow as I did not get any answer there. I would like to apply the methods For example, this is my figure import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import seaborn.objects as so
df = pd.DataFrame(np.arange(5*3).reshape(5,3), columns=["A","B","C"])
df["C"] = df["C"].apply(lambda x: x > 5)
fig = plt.figure()
fg = ((so.Plot(df, x="A", y= "B", group = "C")
.add(so.Line(linewidth = 0.9)))
.facet(col = "C")
.on(fig)
.plot()) And this is the function I would like to apply on each axe of the FacetGrid. This function write a text on each axe displaying the number of data used for the plot. def show_counts(color, data):
ax = plt.gca()
ax.text(0.5, 0.95, f'Count: {len(data)}', ha='center', transform=ax.transAxes)
fg.map_dataframe(show_counts) However, from the last line of code, I get the following error : AttributeError: 'Plotter' object has no attribute 'map_dataframe' Would there be a way to access the data of each axe and apply a function to it ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, unfortunately this is not possible, the objects interface does not use |
Beta Was this translation helpful? Give feedback.
Hi, unfortunately this is not possible, the objects interface does not use
FacetGrid
internally; they're completely separate systems.