0

I am trying to use graph module for plot and trace_values but I come across with this error:

No module named 'graph'

Any help with be greatly appreciated!

import plotly
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode(connected=True)

from graph import plot, trace_values

x_values = list(range(-30, 30, 1))
y_values = list(map(lambda x: output_at(three_x_squared_minus_eleven, x),x_values))

three_x_squared_minus_eleven_trace  = trace_values(x_values, y_values, mode = 'lines')
plot([three_x_squared_minus_eleven_trace], {'title': '3x^2 - 11'})
3
  • 1
    are you sure the name of the module is graph ? Commented Jul 18, 2019 at 17:53
  • 1
    Are you sure that the graph module is installed on your system? Also, the module named graph at PyPI.org is not about graphing but about the data structure about a network. That module is in alpha status and has not been updated since 2005. Are you sure this is what you want? Commented Jul 18, 2019 at 17:54
  • It seems that the OP uses plotly so this explains the error. I have provided an answer. Commented Jul 18, 2019 at 18:01

2 Answers 2

1

Your snippet looks like the one from this GitHub repository, I found the exact same snippet of code defined in their README.

They have defined another python module named graph in this repository.

In this context, the

from graph import plot, trace_values

is legit.

I suppose you don't have this module locally? If you git clone their repo and run the same script the function should properly load.

If you are looking for a Python graph library, you can take a look at NetworkX.

Sign up to request clarification or add additional context in comments.

Comments

0

You are using plotly and probably following some kind of tutorial like this. You need to define these functions. You need the following to make it work:

import plotly
from plotly.offline import iplot, init_notebook_mode

init_notebook_mode(connected=True)

def plot(figure):
    plotly.offline.iplot(figure)

def trace_values(x_values, y_values, mode = 'markers', name="data"):
    pass

sample_trace = {'x': [1, 2, 3], 'y': [2, 3, 4]}
other_sample_trace = {'x': [2, 3, 4], 'y': [5, 3, 4]}
sample_figure = {'data': [sample_trace, other_sample_trace], 'layout': {'title': 'Our sample plot'}}
plot(sample_figure)

EDIT 1:

Apparently there is a Github page for this. You can see the function definition here: https://github.com/learn-co-students/introduction-to-derivatives-lab-data-science-alpha/blob/master/graph.py

In this context, from graph import plot, trace_values can be used given that the repository is cloned.

Just download the repository from here and then from graph import plot, trace_values should work if you are inside the folder (introduction-to-derivatives-lab-data-science-alpha-master)

Comments

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.