pandas/matplotlib-on-frame
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| pandas | info | none, edit by hand | All versions |
Drawing frame columns with matplotlib or seaborn gives a chart that xpd's plotly rules cannot check. Set the pandas plotting backend to plotly and draw with df.plot, which gave the same values as a plotly figure.
plt.scatter(df["score"], df["cost"])pd.options.plotting.backend = "plotly"
df.plot.scatter(x="score", y="cost")What the rule reports
Section titled “What the rule reports”The rule reports plt.plot, plt.scatter and plt.bar on two columns of one frame, plt.hist on one column, and sns.scatterplot, sns.histplot and sns.boxplot with data=. The plot accessor drew the same values with the plotly backend. plt and sns must come from the import of matplotlib.pyplot and of seaborn.
| Left alone | Reason |
|---|---|
sns.barplot and sns.lineplot |
seaborn draws the mean of each group, and plotly draws every row |
plt.barh |
it takes the labels first, and with plotly df.plot.barh takes the values as x |
The matplotlib column selectors must be string labels. Plotly chooses its own histogram bins, and its bin count parameter is nbins. |
How to fix it
Section titled “How to fix it”xpd has no automatic fix, so make the change by hand.
Diagnostic message
Section titled “Diagnostic message”This draws two columns of $DF with matplotlib. With pd.options.plotting.backend = "plotly", $DF.plot.$KIND(x=$A, y=$B) draws the same values as a plotly figure, which xpd checks with its plotly rules.See all rules in the pandas pack.