-
Notifications
You must be signed in to change notification settings - Fork 31
/
Neptune_Plotting_Support.py
120 lines (88 loc) · 2.78 KB
/
Neptune_Plotting_Support.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Import neptune and initialize a new run
import neptune
run = neptune.init_run(
api_token=neptune.ANONYMOUS_API_TOKEN,
project="common/plotting",
tags=["script"],
)
# Log Altair charts to Neptune
## Create a sample chart
import altair as alt
from vega_datasets import data
source = data.cars()
brush = alt.selection_interval()
points = (
alt.Chart(source)
.mark_point()
.encode(
x="Horsepower:Q",
y="Miles_per_Gallon:Q",
color=alt.condition(brush, "Origin:N", alt.value("lightgray")),
)
.add_params(brush)
)
bars = (
alt.Chart(source)
.mark_bar()
.encode(y="Origin:N", color="Origin:N", x="count(Origin):Q")
.transform_filter(brush)
)
chart = points & bars
## Log interactive chart to Neptune
run["altair"].upload(chart)
# Log Bokeh charts to Neptune
## Create a sample chart
import numpy as np
from bokeh.plotting import figure, output_notebook, show
N = 500
x = np.linspace(0, 10, N)
y = np.linspace(0, 10, N)
xx, yy = np.meshgrid(x, y)
d = np.sin(xx) * np.cos(yy)
p = figure(tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")])
p.x_range.range_padding = p.y_range.range_padding = 0
p.image(image=[d], x=0, y=0, dw=10, dh=10, palette="Spectral11", level="image")
p.grid.grid_line_width = 0.5
## Log interactive chart to Neptune
run["bokeh"].upload(p)
# Log folium (leaflet) maps to Neptune
## Create a sample map
import folium
m = folium.Map()
## Log interacive map to Neptune
m.save("map.html")
run["folium"].upload("map.html")
# Log matplotlib charts to Neptune
## Create a sample chart
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(42)
data = np.random.randn(2, 100)
figure, ax = plt.subplots(2, 2, figsize=(5, 5))
ax[0, 0].hist(data[0])
ax[1, 0].scatter(data[0], data[1])
ax[0, 1].plot(data[0], data[1])
## Log static chart to Neptune
run["matplotlib-static"].upload(figure)
## Log interactive chart to Neptune
from neptune.types import File
run["matplotlib-interactive"].upload(File.as_html(figure, include_plotlyjs="cdn"))
# Log Plotly charts to Neptune
## Create a sample chart
import plotly.express as px
df = px.data.iris()
fig = px.scatter_3d(df, x="sepal_length", y="sepal_width", z="petal_width", color="species")
## Log interactive chart to Neptune
run["plotly"].upload(fig, include_plotlyjs="cdn")
# Log Seaborn charts to Neptune
## Create a sample chart
import seaborn as sns
df = sns.load_dataset("penguins")
plot = sns.pairplot(df, hue="species")
## Log chart to Neptune
run["seaborn"].upload(plot)
# Stop Neptune run
run.stop()
# Explore the charts in Neptune
# The charts can be found in the **All metadata** section.
# You can also explore this example run: https://app.neptune.ai/o/showcase/org/plotting/runs/details?viewId=standard-view&detailsTab=metadata&shortId=PLOT-2&path=&attribute=altair