Platform
Resources
Pricing
Sign in
Get started
Observable
The end-to-end solution for building and hosting better data apps, dashboards, and reports.
Workspace
Fork
Public
Plot for Matplotlib Users
By
Ayodele Odubela
Edited
Jan 25, 2023
2 forks
1 star
1
Plot for Matplotlib Users
Overview
Scatterplots
Histograms
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data
=
Array
.
from
(
{
length
:
range
}
,
(
_
,
i
)
=>
{
return
{
x
:
4
+
d3
.
randomNormal
(
0
,
2
)
(
)
,
y
:
4
+
d3
.
randomNormal
(
0
,
2
)
(
)
,
sizes
:
d3
.
randomUniform
(
15
,
80
)
(
)
,
color
:
d3
.
randomUniform
(
15
,
80
)
(
)
}
}
)
Insert cell
Insert cell
Plot
.
plot
(
{
grid
:
true
,
// by default Plot has "grid: false", to show a grid we set grid to 'true'
marks
:
[
Plot
.
frame
(
)
,
// draws the frame mark around the Plot
Plot
.
dot
(
data
,
{
x
:
"x"
,
y
:
"y"
,
fill
:
"color"
,
r
:
"sizes"
,
}
)
]
,
color
:
{
scheme
:
"Blues"
,
// todo: say something about defaults / add link to color cheatsheet
domain
:
[
0
,
100
]
,
// this is the equivalent of the vmin / vmax in matplotlip
}
,
x
:
{
domain
:
[
0
,
8
]
,
//
ticks
:
d3
.
range
(
1
,
8
)
// equivalent of xticks=np.arange(1, 8)
}
,
y
:
{
domain
:
[
0
,
8
]
,
ticks
:
d3
.
range
(
1
,
8
)
// equivalent of yticks=np.arange(1, 8)
}
,
}
)
Insert cell
Insert cell
Insert cell
Plot
.
plot
(
{
marks
:
[
Plot
.
frame
(
{
stroke
:
"#ccc"
}
)
,
// draws a light grey (#ccc) frame mark around the Plot
Plot
.
dot
(
data
,
{
x
:
"x"
,
y
:
"y"
,
fill
:
"color"
,
r
:
"sizes"
,
}
)
]
,
color
:
{
scheme
:
"Blues"
,
// todo: say something about defaults / add link to color cheatsheet
legend
:
true
,
ticks
:
10
,
range
:
[
.1
,
.9
]
}
,
height
:
300
,
width
:
350
}
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot
.
plot
(
{
marks
:
[
Plot
.
frame
(
{
stroke
:
"#ccc"
}
)
,
// draws a light grey (#ccc) frame mark around the Plot
Plot
.
dot
(
data
,
{
x
:
"x"
,
y
:
"y"
,
fill
:
"color"
,
stroke
:
"#aaa"
,
// add a light grey stroke so it's easier to see the points
strokeWidth
:
.2
,
r
:
"sizes"
,
title
:
d
=>
'data: '
+
'\n'
+
'x: '
+
format
(
d
.
x
)
+
'\n'
+
'y: '
+
format
(
d
.
y
)
+
'\n'
+
'color: '
+
format
(
d
.
color
)
+
'\n'
+
'size: '
+
format
(
d
.
sizes
)
// for the tooltip
}
)
]
,
color
:
{
scheme
:
colorscheme
,
// todo: say something about defaults / add link to color cheatsheet
legend
:
true
,
ticks
:
10
,
range
:
[
.1
,
.9
]
,
reverse
:
reverseScheme
}
,
height
:
300
,
width
:
350
}
)
Insert cell
format
=
d3
.
format
(
",.2f"
)
Insert cell
##
Resources
Insert cell
####
Other examples to recreate
-
[
Histograms
]
(
https://matplotlib.org/stable/plot_types/stats/hist_plot.html
)
-
[
Box Plot
]
(
https://matplotlib.org/stable/plot_types/stats/boxplot_plot.html
)
-
(point to cheat sheets for ticks)
-
Animation (import scrubber)
Insert cell
Insert cell
import
{
addTooltips
}
from
"@mkfreeman/plot-tooltip"
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
range
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
colorscheme
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
reverseScheme
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
format
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML