1

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.