将matplot转换为plotly

时间:2019-07-02 04:49:50

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

我想知道是否有可能像我在下面尝试的那样将索引的名称从matplot导入到plotly中:

图表栏:

var expect = require('expect.js');
var sinon = require('sinon');
var rewire = require('rewire');
var context = require('context') // give correct path here
var app = rewire('./util.js');

var fakeContext = {
  getVariable: function(s) {}
}

beforeEach(function () {
  contextGetVariableMethod = sinon.stub(context, 'getVariable');
});

afterEach(function() {
  contextGetVariableMethod.restore();
});

describe('feature: concat', function() {
  it('should concat two strings', function() {
    contextGetVariableMethod.withArgs('first_name').returns("SS");
    var concat = app.__get__('concat');
    expect(concat("988")).to.equal("988SS");
  });
}); 

enter image description here

将Matplot栏转换为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)

enter image description here

2 个答案:

答案 0 :(得分:0)

尝试一下

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')

答案 1 :(得分:0)

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)

bar chart of a Pandas series