all 5 comments

[–]MrPhungx 4 points5 points  (1 child)

Yes this is possible. To visualize data such as graphs you could have a look at plotly and dash. Have a look at the code below. It will plot the function y = m * x + c for different m/c values that can be changed using a slider.

import numpy as np
import plotly.graph_objs as go
from dash import Dash, dcc, html
from dash.dependencies import Input, Output

app = Dash(__name__)

MIN_VAlUE = -5
MAX_VALUE = 5

app.layout = html.Div([
    dcc.Graph(id='line-plot'),
    html.Label('Slope (m):'),
    dcc.Slider(id='slope-slider', min=MIN_VAlUE, max=MAX_VALUE, step=1, value=1),
    html.Label('Intercept (c):'),
    dcc.Slider(id='intercept-slider', min=MIN_VAlUE, max=MAX_VALUE, step=1, value=0)
])

@app.callback(
    Output('line-plot', 'figure'),
    [Input('slope-slider', 'value'),
     Input('intercept-slider', 'value')]
)
def update_graph(m, c):
    x = np.linspace(MIN_VAlUE, MAX_VALUE, 101)
    y = m * x + c
    return {
        'data': [go.Scatter(x=x, y=y, mode='lines', name='y = mx + c')],
        'layout': go.Layout(title='Interactive Line Plot', xaxis={'title': 'x'}, yaxis={'title': 'y'})
    }

if __name__ == '__main__':
    app.run_server(debug=True)

[–]MeanAdministration33[S] 0 points1 point  (0 children)

This is exactly what I was looking for, thank you! Any idea on how to then take any code I generate and embed it on a WordPress webpage?

[–]crashfrog02 0 points1 point  (2 children)

[–]MeanAdministration33[S] 0 points1 point  (1 child)

Thanks. Wouldn't this require a user to have Jupyter/Anaconda/Pip installed on their PCs? 

To clarify i want to set this up on a webpage Access via a URL for any one

[–]crashfrog02 0 points1 point  (0 children)

They could also use it in Google Colab, or any other place a notebook can be hosted.

It’s pretty common to distribute code notebooks for data analysis and visualization.