【问题标题】:Converting matplot to plotly将 matplotlib 转换为 plotly
【发布时间】:2019-11-12 16:34:28
【问题描述】:

我想知道是否可以将 index 的名称从 matplot 导入 plotly,如下所示:

Matplot 栏:

fig = plt.figure(figsize = (10, 5))
ax = fig.add_subplot(111)

pd.Series([10, 20, 30, 40, 50], index =['a', 'b', 'c', 'd', 'e']).plot.bar(ax = ax)

将 Matplot Bar 转换为 Plotly:

fig = plt.figure(figsize = (10, 5))
ax = fig.add_subplot(111)

pd.Series([10, 20, 30, 40, 50], index =['a', 'b', 'c', 'd', 'e']).plot.bar(ax = ax)

py.iplot_mpl(fig)

【问题讨论】:

    标签: python python-3.x pandas matplotlib plotly


    【解决方案1】:

    试试这个,

    import plotly.plotly as py
    import plotly.graph_objs as go
    
    data = [go.Bar(
            x=['a', 'b', 'c', 'd', 'e'],
            y=[10, 20, 30, 40, 50]
    )]
    
    py.plot(data, filename='basic-bar')
    

    【讨论】:

    • 您好,很抱歉造成混乱,但我想在这里问的是为什么每当将 matplot 转换为 plotly 时都不会导入索引,但感谢您的回答。这将完全创建一个显示索引的情节
    【解决方案2】:

    plotly.express(在plotly==5.1.0 上测试)识别pandas.Series 的索引。

    import pandas as pd
    import plotly.express as ex
    
    s = pd.Series([10, 20, 30, 40, 50], index=['a', 'b', 'c', 'd', 'e'])
    px.bar(s)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-06
      • 1970-01-01
      • 2018-11-14
      • 1970-01-01
      • 1970-01-01
      • 2015-08-12
      • 2022-10-25
      相关资源
      最近更新 更多