Plotly 中的列总和条形图
Column Sum bar chart in Plotly
我有以下数据集
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame()
df['Chinese'] = [0,1,1,1,0,0,1]
df['Italian'] = [1,0,0,0,1,1,0]
df[['Italian','Chinese']].sum().plot.bar()
plt.show()
这给了我一个使用 Matplotlib 的绘图,我如何使用 Plotly 获得相同的绘图。我无法在 plotly 中找到聚合图。
我需要它的原因是我需要将它与 Dash App 集成。
您可以将 plotly 设置为 for pandas with:
pd.options.plotting.backend = "plotly"
然后使用:
df[['Italian','Chinese']].sum().plot(kind = 'bar')
情节
完整代码:
import pandas as pd
import matplotlib.pyplot as plt
pd.options.plotting.backend = "plotly"
df = pd.DataFrame()
df['Chinese'] = [0,1,1,1,0,0,1]
df['Italian'] = [1,0,0,0,1,1,0]
df[['Italian','Chinese']].sum().plot(kind = 'bar')
我有以下数据集
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame()
df['Chinese'] = [0,1,1,1,0,0,1]
df['Italian'] = [1,0,0,0,1,1,0]
df[['Italian','Chinese']].sum().plot.bar()
plt.show()
这给了我一个使用 Matplotlib 的绘图,我如何使用 Plotly 获得相同的绘图。我无法在 plotly 中找到聚合图。
我需要它的原因是我需要将它与 Dash App 集成。
您可以将 plotly 设置为
pd.options.plotting.backend = "plotly"
然后使用:
df[['Italian','Chinese']].sum().plot(kind = 'bar')
情节
完整代码:
import pandas as pd
import matplotlib.pyplot as plt
pd.options.plotting.backend = "plotly"
df = pd.DataFrame()
df['Chinese'] = [0,1,1,1,0,0,1]
df['Italian'] = [1,0,0,0,1,1,0]
df[['Italian','Chinese']].sum().plot(kind = 'bar')