Home > Mobile >  Pandas: plot() without legend but getting TypeError
Pandas: plot() without legend but getting TypeError

Time:04-06

I'm getting a TypeError when setting legend=False but according to the documentation this shouldn't be a problem. What am I doing wrong?

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.html

import pandas as pd
pd.options.plotting.backend = "plotly"

row = df.iloc[0]
row.plot(kind='bar', legend=False)

TypeError: bar() got an unexpected keyword argument 'legend'

The data in df.iloc[0] looks like this

RevolvingUtilizationOfUnsecuredLines    0.223647
age                                     0.071428
NumberOfTime30-59DaysPastDueNotWorse    1.130581
DebtRatio                               0.361630
MonthlyIncome                          -0.277019
NumberOfOpenCreditLinesAndLoans         0.025073
NumberOfTimes90DaysLate                -0.342467
NumberRealEstateLoansOrLines            0.728451
NumberOfTime60-89DaysPastDueNotWorse   -0.196677
NumberOfDependents                     -0.061967
MonthlyIncomePerPerson                 -0.029531
isRetired                               0.016656
Q1_Monthly_Income_True                  0.032911
Q3_Monthly_Income_True                 -0.000393
Q1_Revolving_True                       0.023684
Q3_Revolving_True                       0.273972

CodePudding user response:

You are generating a plotly figure. Hence change the layout of the return

pd.options.plotting.backend = "plotly"
df.iloc[1].plot(kind="bar").update_layout(showlegend=False)
  • Related