SkillAgentSearch skills...

PyPlotly.jl

Pythonista friendly Julia interface for plotly

Install / Use

/learn @AtelierArith/PyPlotly.jl
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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
<img width="600" alt="image" src="https://user-images.githubusercontent.com/16760547/166682557-260cc5a0-1321-4c07-9080-26459cf85706.png">

Pluto

<img width="600" alt="image" src="https://user-images.githubusercontent.com/16760547/166682859-f3d342e6-2cc5-414b-b9a5-ec918625b6f7.png">

Code is available from here.

Appendix

View on GitHub
GitHub Stars5
CategoryDevelopment
Updated3y ago
Forks1

Languages

Julia

Security Score

75/100

Audited on Oct 25, 2022

No findings