如何防止图形堆积的条形图合并为接近的x轴值?

时间:2018-04-20 10:38:05

标签: plotly plotly.js

在绘制堆积条形图时,具有非常接近的x轴值的条形结合在一起。 如何禁用合并栏? [Plot attatched]

我的代码:

  

情节。版本 ='2.5.1'
sys.version ='3.6.5 | Anaconda,Inc。|   (默认情况下,2018年3月29日,13:32:41)[MSC v.1900 64 bit(AMD64)]'

import pandas as pd
import cufflinks as cf
import plotly
plotly.offline.init_notebook_mode()

all_data = [
(‘2018-04-09’, ‘10:10:11’, [‘s4’,8], [‘s2’,20],[‘s1’,10],[‘s6’,22],[‘s7’,24]),
(‘2018-04-09’, ‘10:10:12’, [‘s1’,10],[‘s2’,15],[‘s3’,5],[‘s4’,7],[‘s5’,6]),
(‘2018-04-10’, ‘10:30:11’, [‘s4’,10],[‘s5’,6], [‘s6’,3],[‘s1’,2],[‘s2’,7]),
(‘2018-04-15’, ‘10:18:11’, [‘s1’,10],[‘s2’,15],[‘s3’,5],[‘s4’,7],[‘s5’,6]),
(‘2018-04-18’, ‘10:20:11’, [‘s4’,8], [‘s2’,20],[‘s1’,10],[‘s6’,22],[‘s7’,24]),
(‘2018-04-18’, ‘10:20:12’, [‘s4’,10],[‘s5’,6], [‘s6’,3],[‘s1’,2],[‘s2’,7])
]

df = pd.DataFrame(all_data, columns = list(“ABCDEFG”))
df[“day/time”] = pd.to_datetime(df[“A”] + " " + df[“B”])
df = df.melt(id_vars = [“day/time”], value_vars = [“C”, “D”, “E”,“F”,“G”])
df[[“category”, “val”]] = pd.DataFrame(df.value.values.tolist(), index = df.index)
df = df.pivot(index = “day/time”, columns = “category”, values = “val”)

fig = df.iplot(kind=‘bar’, barmode=‘stack’, asFigure=True)
plotly.offline.plot(fig,filename=“top1.html”)

例如在'2018-04-09 10:10:11'下面的第一个栏中& '2018-04-09 10:10:12'合并。 enter image description here

0 个答案:

没有答案