Python dynamic objects not defined anywhere? (Plotly lib)

≯℡__Kan透↙ 提交于 2019-12-01 11:37:04

问题


I'm no python expert, but know about programming in general.
I've started using https://github.com/plotly/plotly.py/ for doing charts in python but I'm finding problems with 1) getting IDE autocomplete to work and 2) exploring the api (particularly because of 1).

One particular thing I dont understand is how this even works:

from plotly.graph_objs import *
traces = []
traces.append(Scatter(
    x=val.x,
    y=val.y,
    name=str(key),
    error_y=dict(
        type='data',
        array=val.err,
        visible=True,
        width=1,
        )
    ))

plotly.offline.plot(traces, filename='basic-line.html', auto_open=False)

I went to the graph_objs source at https://github.com/plotly/plotly.py/blob/master/plotly/graph_objs/graph_objs.py and found no reference to Scatter whatsoever.

Pycharm doesn't resolve the dependency and shows errors on all it's properties, and of course no docs pop up.

Going to the source of the plot function (https://github.com/plotly/plotly.py/blob/master/plotly/offline/offline.py#L314) I see that the first parameter can be a list or a dict, which gets passed to tools.py, a whopping 7k line archive, with a particular method of interest:

def return_figure_from_figure_or_data(figure_or_data, validate_figure):
    from plotly.graph_objs import graph_objs
    if validate_figure:

        try:
            graph_objs.Figure(figure)

(found here https://github.com/plotly/plotly.py/blob/master/plotly/tools.py#L1422)

Once again, I go to the graph_objs file trying to find the Figure() method or class, but there is none.

While I'm not python expert, this is not something I've found in the past, and sounds very un-pythonic to me. So the questions are:

  1. What kind of python wizardry is this? How is it called so I can google it up?
  2. How does it work in runtime?
  3. Is it an acceptable/good api design? Is it pythonic?
  4. How can I try to explore such a dynamic api without IDE support? I cant grep the code either, as "Figure(" does not appear to be defined anywhere.

来源:https://stackoverflow.com/questions/38021683/python-dynamic-objects-not-defined-anywhere-plotly-lib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!