Skip to content

AtelierArith/PyPlotly.jl

Repository files navigation

PyPlotly

Build Status

Stable

Dev

Introduction

I know there are Plotly.jl and PlotlyJS.jl. But, it would be nice to provide a Pythonista-friendly Julia interface for plotly since there are lots of examples on the internet regarding plotly written in Python.

Just give it a try

$ pip3 install numpy pandas plotly
$ git clone https://github.com/AtelierArith/PyPlotly.jl.git
$ cd PyPlotly
$ julia --project=@. -e 'using Pkg; Pkg.isinstance()'

How to use

Let's assume you've written a Python script something like:

import plotly.graph_objects as go

# Create random data with numpy
import numpy as np
np.random.seed(1)

N = 100
random_x = np.linspace(0, 1, N)
random_y0 = np.random.randn(N) + 5
random_y1 = np.random.randn(N)
random_y2 = np.random.randn(N) - 5

fig = go.Figure()

# Add traces
fig.add_trace(go.Scatter(x=random_x, y=random_y0,
                    mode='markers',
                    name='markers'))
fig.add_trace(go.Scatter(x=random_x, y=random_y1,
                    mode='lines+markers',
                    name='lines+markers'))
fig.add_trace(go.Scatter(x=random_x, y=random_y2,
                    mode='lines',
                    name='lines'))

fig.show()

The example above is taken from Line and Scatter Plots. You can translate the python code into Julia code as below:

using PyPlotly # this exports `go` and `px`

using Random
Random.seed!(1)

N = 100
random_x = range(0, 1, length=N)
random_y0 = randn(N) .+ 5
random_y1 = randn(N)
random_y2 = randn(N) .- 5

fig = go.Figure()

# Add traces
fig.add_trace(go.Scatter(x=random_x, y=random_y0,
                    mode="markers",
                    name="markers"))
fig.add_trace(go.Scatter(x=random_x, y=random_y1,
                    mode="lines+markers",
                    name="lines+markers"))
fig.add_trace(go.Scatter(x=random_x, y=random_y2,
                    mode="lines",
                    name="lines"))

fig

Display object in notebook

JupyterLab

Try running the following example in your notebook

using PyPlotly

df = px.data.iris()
fig = px.scatter(
    df,
    x="sepal_width",
    y="sepal_length",
    color="species",
    size="petal_length",
    hover_data=["petal_width"],
)
fig

image

Pluto

image

Code is available from here.

Appendix

About

Pythonista friendly Julia interface for plotly

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published