plotly 条形图没有显示数据

plotly bar chart no data is shown

我正在使用 go.Bar() 绘制多系列条形图,我不确定为什么没有显示数据。图表是空的。对于相同的数据帧,我可以在使用 matplotlib 时得到第二个数字。

这是 codes/dataframe 和情节。感谢您的帮助

import plotly.graph_objects as go
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

init_notebook_mode()
data=[]
for col in weights_df.columns:
    trace=go.Bar(
            x=weights_df.index,
            y=weights_df[col].values,
            name = col,
            )
    data.append(trace)
        
layout = go.Layout(barmode = 'stack')
# layout = go.Layout(barmode = 'group')
fig = go.Figure(data = data, layout = layout)
iplot(fig)

weights_df.to_dict()
{'FB': {0.001: -1.2892401228940826e-25,
  0.002: -2.2227391251386763e-22,
  0.003: 2.230454389710684e-22,
  0.006: 1.1129693327647472e-22,
  0.01: -1.1232118315603586e-22,
  0.018: -1.1334956156148527e-22,
  0.032: 1.1527688641147928e-22,
  0.056: -5.315215920568091e-23,
  0.1: -3.4189532042683237e-23,
  0.178: 1.2264912229492635e-22,
  0.316: 8.740551910124495e-23,
  0.562: -8.29172316524412e-23,
  1.0: -5.477536011110415e-23,
  1.778: 0.26529561778820837,
  3.162: 0.19277185168055397,
  5.623: 0.12224038565596697,
  10.0: 0.0657728318037745,
  17.783: 0.023672603112219005,
  31.623: 5.461474184405858e-23,
  56.234: -1.6031976237442814e-23,
  100.0: -5.643191492335551e-23,
  177.828: -8.128793084119128e-23,
  316.228: 4.767180594401383e-23,
  562.341: -5.29681899397754e-23,
  1000.0: -6.184000141743679e-23},
 'TSLA': {0.001: -1.0610079180939896e-25,
  0.002: -1.1121102209917622e-22,
  0.003: 8.87060573285422e-25,
  0.006: 2.7073996774457937e-25,
  0.01: -5.658166996462947e-23,
  0.018: 8.13457637865462e-23,
  0.032: 1.773982377925747e-23,
  0.056: 5.783579919287192e-23,
  0.1: -1.1986116086429181e-22,
  0.178: -1.5292738132543234e-22,
  0.316: 0.2217144450819861,
  0.562: 0.39681921782078755,
  1.0: 0.49528786776987993,
  1.778: 0.36592750532311275,
  3.162: 0.2012747494445739,
  5.623: 0.10286766942125149,
  10.0: 0.04218692438618542,
  17.783: 0.006285771685368587,
  31.623: -6.810636437846125e-23,
  56.234: -2.4431540308975666e-23,
  100.0: 2.3265944539231562e-23,
  177.828: 1.505795211107229e-23,
  316.228: 6.000929347320952e-24,
  562.341: -1.8957438080100863e-23,
  1000.0: -3.3509114511488615e-24},
 'AMZN': {0.001: -1.1115579577914626e-22,
  0.002: -3.3330434234847433e-22,
  0.003: 2.230715699531167e-22,
  0.006: -1.1074453050634317e-22,
  0.01: -2.2338930367230656e-22,
  0.018: -1.1343123701409405e-22,
  0.032: 4.352226385295074e-24,
  0.056: -1.0863625323363557e-22,
  0.1: 2.1875404677854116e-23,
  0.178: 2.9105273879013967e-22,
  0.316: 3.1152049993852455e-23,
  0.562: 3.5793712842998726e-25,
  1.0: 2.872913812213987e-24,
  1.778: -3.2278126329104576e-23,
  3.162: -3.4418137316917784e-23,
  5.623: 0.08872914037819903,
  10.0: 0.17062679236180953,
  17.783: 0.20891391049021021,
  31.623: 0.22275319321317139,
  56.234: 0.2225020063030134,
  100.0: 0.21921312429586165,
  177.828: 0.2165241588672629,
  316.228: 0.21430357083128293,
  562.341: 0.2130548424124283,
  1000.0: 0.2123526308185666},
 'MSFT': {0.001: -1.1115487409686761e-22,
  0.002: -2.22280406016246e-22,
  0.003: 1.1205727327928304e-22,
  0.006: 2.8649534965529014e-25,
  0.01: -1.123581283210036e-22,
  0.018: -1.134160075227621e-22,
  0.032: 1.1543050340483144e-22,
  0.056: 2.461227874325761e-24,
  0.1: -8.896999783451449e-23,
  0.178: 1.8038322582470612e-22,
  0.316: 8.61736918447801e-23,
  0.562: 4.04489773065989e-25,
  1.0: -7.567050919944326e-25,
  1.778: 1.7510952459312536e-23,
  3.162: -2.7836899651137116e-23,
  5.623: -2.847532154376053e-23,
  10.0: -3.494443358854006e-23,
  17.783: -4.7877943014587617e-23,
  31.623: -1.988218425222294e-23,
  56.234: -4.3151523985448414e-23,
  100.0: 4.9954731564463044e-23,
  177.828: 0.0014505327043787966,
  316.228: 0.003490375040042166,
  562.341: 0.00463746268225853,
  1000.0: 0.005282517467092056},
 'AAPL': {0.001: 1.1087950294014152e-22,
  0.002: -3.3332089651291097e-22,
  0.003: 1.1210535196484387e-22,
  0.006: 2.861861916768973e-25,
  0.01: -1.124604032052154e-22,
  0.018: -1.1359787502874796e-22,
  0.032: 1.1558964122813247e-22,
  0.056: -1.0856404965856768e-22,
  0.1: -8.795785653766981e-23,
  0.178: 1.839926102440878e-22,
  0.316: -2.8077773560338917e-23,
  0.562: 3.5802670131317777e-25,
  1.0: -6.150671080738591e-23,
  1.778: 3.744002697235152e-23,
  3.162: -1.951371794495665e-23,
  5.623: 1.758261934661116e-23,
  10.0: 0.03629456333575671,
  17.783: 0.0704812611642971,
  31.623: 0.08448746273570926,
  56.234: 0.08704959617377002,
  100.0: 0.08646527646833846,
  177.828: 0.08573775764107025,
  316.228: 0.08499197336032115,
  562.341: 0.0845725880395784,
  1000.0: 0.08433675034254642},
 'NVDA': {0.001: -1.597227752178294e-25,
  0.002: -2.2232869255741088e-22,
  0.003: 2.232179126628466e-22,
  0.006: 2.9322220386867886e-25,
  0.01: -1.1262991766711548e-22,
  0.018: -2.8774663219498556e-24,
  0.032: 1.1591407371762525e-22,
  0.056: 2.518711790236575e-24,
  0.1: -8.604916819607207e-23,
  0.178: 1.905579519421392e-22,
  0.316: -3.4396208546596154e-23,
  0.562: 3.6240639028938107e-25,
  1.0: 7.777493788249112e-24,
  1.778: 8.85294773711592e-23,
  3.162: 0.2614973684473394,
  5.623: 0.44430798978412855,
  10.0: 0.5307056390508103,
  17.783: 0.5693505550474228,
  31.623: 0.5940888791694633,
  56.234: 0.6069371628532166,
  100.0: 0.6146880240835736,
  177.828: 0.6189707513251296,
  316.228: 0.6213150495918994,
  562.341: 0.6226333453858762,
  1000.0: 0.6233746775896544},
 'AMD': {0.001: 1.1089089683875938e-22,
  0.002: -2.2227832731537543e-22,
  0.003: 1.1203920822588652e-22,
  0.006: 2.2232226627306907e-22,
  0.01: -1.1234612048060103e-22,
  0.018: 1.0865050446271897e-22,
  0.032: 4.318313523839443e-24,
  0.056: -1.086372531679886e-22,
  0.1: -8.935925827533034e-23,
  0.178: 6.825626495785666e-23,
  0.316: 3.107905684181859e-23,
  0.562: 5.587137919327502e-23,
  1.0: -2.8261298397990225e-23,
  1.778: 0.028071921708011805,
  3.162: 0.08350163062807371,
  5.623: 0.04106680193294852,
  10.0: -2.2493821935771765e-23,
  17.783: -9.756286042020316e-24,
  31.623: -1.9891243136714126e-23,
  56.234: 4.3433499784918445e-23,
  100.0: 8.167770032571491e-23,
  177.828: 1.1697070181406983e-22,
  316.228: -4.812772852930743e-25,
  562.341: -6.817056218036263e-23,
  1000.0: 6.126085296279434e-23},
 'HD': {0.001: -1.1116600728620077e-22,
  0.002: -2.2230020449441485e-22,
  0.003: 1.0885181279089784e-24,
  0.006: 1.1130931594598529e-22,
  0.01: -1.1246949042062036e-22,
  0.018: -1.1361408820959906e-22,
  0.032: 4.588324817530307e-24,
  0.056: 2.4653142762742788e-24,
  0.1: -8.784206084332084e-23,
  0.178: 7.335588099203538e-23,
  0.316: 8.235205226317895e-23,
  0.562: -5.515552584110866e-23,
  1.0: -6.376537360142911e-23,
  1.778: 1.4338363046428007e-23,
  3.162: 0.06912986861816069,
  5.623: 0.09416188648397032,
  10.0: 0.0973120949648873,
  17.783: 0.09297518589032384,
  31.623: 0.0883352168128106,
  56.234: 0.08351123467000014,
  100.0: 0.07963357515222619,
  177.828: 0.0773167994621583,
  316.228: 0.07589903117645416,
  562.341: 0.07510176147985859,
  1000.0: 0.07465342378214068},
 'NKE': {0.001: -1.0502554203995966e-25,
  0.002: -3.3325371242742737e-22,
  0.003: -5.463428005309555e-23,
  0.006: -1.1075514451041526e-22,
  0.01: -5.657075382914179e-23,
  0.018: -1.6843473882477242e-22,
  0.032: 1.7034973908205852e-22,
  0.056: 1.1331692047246097e-22,
  0.1: -1.478319163925075e-22,
  0.178: -1.0847666391881473e-22,
  0.316: 1.8259913670682134e-22,
  0.562: 8.361304495434946e-23,
  1.0: 2.4922550207677423e-23,
  1.778: 3.331873105860055e-23,
  3.162: 1.0581747076686626e-23,
  5.623: 1.756139569572509e-23,
  10.0: -7.372163848564858e-23,
  17.783: -2.8476363280211865e-24,
  31.623: -7.178324009240659e-23,
  56.234: -1.9233866930598144e-23,
  100.0: 5.9464749958017365e-24,
  177.828: 7.533206051093293e-23,
  316.228: -5.790732930279413e-23,
  562.341: 1.4674260484032502e-23,
  1000.0: -7.1888064183705e-24},
 'KO': {0.001: 1.0,
  0.002: 1.0,
  0.003: 1.0,
  0.006: 1.0,
  0.01: 1.0,
  0.018: 1.0,
  0.032: 1.0,
  0.056: 1.0,
  0.1: 1.0,
  0.178: 1.0,
  0.316: 0.7782855549180139,
  0.562: 0.6031807821792124,
  1.0: 0.50471213223012,
  1.778: 0.34070495518066707,
  3.162: 0.1918245311812984,
  5.623: 0.10662612634353523,
  10.0: 0.05710115409677635,
  17.783: 0.02832071261015843,
  31.623: 0.010335248068845306,
  56.234: -3.513219252500413e-23,
  100.0: 3.587427648414208e-23,
  177.828: 6.631360591417912e-24,
  316.228: -1.1010367169872057e-23,
  562.341: 5.496088264932607e-24,
  1000.0: -1.7779421908475062e-23}}

Plotly 认为您的 x 值是数值,并且由于前几个相对较小的数值,Plotly 也将条形的默认宽度设置为较小的值。您可以将它们设为分类:

fig.update_xaxes(type='category')