как строить таблицы с помощью chart_studio на графике - PullRequest
1 голос
/ 02 августа 2020

Эй, я хотел бы построить таблицу, как в этой ссылке: https://plotly.com/python/v3/figure-factory/table/. Я копирую код с этого сайта:

import plotly.plotly as py
import plotly.figure_factory as ff

data_matrix = [['Country', 'Year', 'Population'],
               ['United States', 2000, 282200000],
               ['Canada', 2000, 27790000],
               ['United States', 2005, 295500000],
               ['Canada', 2005, 32310000],
               ['United States', 2010, 309000000],
               ['Canada', 2010, 34000000]]

table = ff.create_table(data_matrix)
py.iplot(table, filename='simple_table')

, но получаю сообщение об ошибке: «Модуль plotly.plotly устарел, пожалуйста, установите пакет chart-studio и используйте вместо него модуль chart_studio.plotly».

Я устанавливаю пакет "chart_studio", и мой код:

import chart_studio.plotly as py
import plotly.figure_factory as ff

data_matrix = [['Country', 'Year', 'Population'],
               ['United States', 2000, 282200000],
               ['Canada', 2000, 27790000],
               ['United States', 2005, 295500000],
               ['Canada', 2005, 32310000],
               ['United States', 2010, 309000000],
               ['Canada', 2010, 34000000]]

table = ff.create_table(data_matrix)
py.iplot(table, filename='simple_table')

, но когда я компилирую, это занимает много времени, и я получаю сообщение об ошибке:

---------------------------------------------------------------------------
PlotlyRequestError                        Traceback (most recent call last)
<ipython-input-75-e57c1b8eaaa0> in <module>
     11 
     12 table = ff.create_table(data_matrix)
---> 13 py.iplot(table, filename='simple_table')

~\anaconda3\lib\site-packages\chart_studio\plotly\plotly.py in iplot(figure_or_data, **plot_options)
    133     if "auto_open" not in plot_options:
    134         plot_options["auto_open"] = False
--> 135     url = plot(figure_or_data, **plot_options)
    136 
    137     if isinstance(figure_or_data, dict):

~\anaconda3\lib\site-packages\chart_studio\plotly\plotly.py in plot(figure_or_data, validate, **plot_options)
    274             grid_filename = filename + "_grid"
    275 
--> 276         grid_ops.upload(
    277             grid=grid,
    278             filename=grid_filename,

~\anaconda3\lib\site-packages\chart_studio\plotly\plotly.py in upload(cls, grid, filename, world_readable, auto_open, meta)
   1085                 payload["parent_path"] = parent_path
   1086 
-> 1087         file_info = _create_or_overwrite_grid(payload)
   1088 
   1089         cols = file_info["cols"]

~\anaconda3\lib\site-packages\chart_studio\plotly\plotly.py in _create_or_overwrite_grid(data, max_retries)
   1548     # Create file
   1549     try:
-> 1550         res = api_module.create(data)
   1551     except exceptions.PlotlyRequestError as e:
   1552         if max_retries > 0 and "already exists" in e.message:

~\anaconda3\lib\site-packages\chart_studio\api\v2\grids.py in create(body)
     16     """
     17     url = build_url(RESOURCE)
---> 18     return request("post", url, json=body)
     19 
     20 

~\anaconda3\lib\site-packages\retrying.py in wrapped_f(*args, **kw)
     47             @six.wraps(f)
     48             def wrapped_f(*args, **kw):
---> 49                 return Retrying(*dargs, **dkw).call(f, *args, **kw)
     50 
     51             return wrapped_f

~\anaconda3\lib\site-packages\retrying.py in call(self, fn, *args, **kwargs)
    204 
    205             if not self.should_reject(attempt):
--> 206                 return attempt.get(self._wrap_exception)
    207 
    208             delay_since_first_attempt_ms = int(round(time.time() * 1000)) - start_time

~\anaconda3\lib\site-packages\retrying.py in get(self, wrap_exception)
    245                 raise RetryError(self)
    246             else:
--> 247                 six.reraise(self.value[0], self.value[1], self.value[2])
    248         else:
    249             return self.value

~\anaconda3\lib\site-packages\six.py in reraise(tp, value, tb)
    701             if value.__traceback__ is not tb:
    702                 raise value.with_traceback(tb)
--> 703             raise value
    704         finally:
    705             value = None

~\anaconda3\lib\site-packages\retrying.py in call(self, fn, *args, **kwargs)
    198         while True:
    199             try:
--> 200                 attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
    201             except:
    202                 tb = sys.exc_info()

~\anaconda3\lib\site-packages\chart_studio\api\v2\utils.py in request(method, url, **kwargs)
    178         content = response.content if response else "No content"
    179         raise exceptions.PlotlyRequestError(message, status_code, content)
--> 180     validate_response(response)
    181     return response

~\anaconda3\lib\site-packages\chart_studio\api\v2\utils.py in validate_response(response)
     80         message = content if content else "No Content"
     81 
---> 82     raise exceptions.PlotlyRequestError(message, status_code, content)
     83 
     84 

PlotlyRequestError: Authentication credentials were not provided.

Кто-нибудь может мне помочь ? Я хочу, чтобы таблица выглядела именно так, как в ссылке

...