Plotly: the 2023-24 Pacific Division's wins as horizontal bars, logos down the y axis, named by nickname (the figure for Plotly.newPlot)
With JavaScript on, plotly.js draws this figure here.
{
"data": [
{
"type": "bar",
"orientation": "h",
"y": [
"Clippers",
"Suns",
"Lakers",
"Kings",
"Warriors"
],
"x": [
51,
49,
47,
46,
46
],
"marker": {
"color": [
"#12173f",
"#29127a",
"#552583",
"#5a2d81",
"#fdb927"
]
}
}
],
"layout": {
"width": 560,
"height": 360,
"xaxis": {
"title": {
"text": "Wins (2023-24)"
}
},
"yaxis": {
"range": [
4.5,
-0.5
],
"tickmode": "array",
"showticklabels": false,
"tickvals": [
"Clippers",
"Suns",
"Lakers",
"Kings",
"Warriors"
],
"ticktext": [
"Clippers",
"Suns",
"Lakers",
"Kings",
"Warriors"
]
},
"margin": {
"l": 107
},
"images": [
{
"source": "https://sdv.nyc3.cdn.digitaloceanspaces.com/assets/public/sha256/d4/d43253c0630f0d3d3a4c3c50ce92c9dbe8d5bf21e3bfd5326920c9487b26dbec.png",
"sizing": "contain",
"layer": "above",
"name": "sdvplot:axis:y:12",
"x": 0,
"y": 0,
"xref": "paper",
"yref": "y",
"sizex": 1,
"sizey": 0.75,
"xanchor": "right",
"yanchor": "middle"
},
{
"source": "https://sdv.nyc3.cdn.digitaloceanspaces.com/assets/public/sha256/5f/5f8932efdb7595069610b11ec2f417d78a9213691c2ba21e2bd491c172397ead.png",
"sizing": "contain",
"layer": "above",
"name": "sdvplot:axis:y:21",
"x": 0,
"y": 1,
"xref": "paper",
"yref": "y",
"sizex": 1,
"sizey": 0.75,
"xanchor": "right",
"yanchor": "middle"
},
{
"source": "https://sdv.nyc3.cdn.digitaloceanspaces.com/assets/public/sha256/82/82fda3df51058c5aad8a52123868f43959017be0c39c886e9aefbb77e6c69c89.png",
"sizing": "contain",
"layer": "above",
"name": "sdvplot:axis:y:13",
"x": 0,
"y": 2,
"xref": "paper",
"yref": "y",
"sizex": 1,
"sizey": 0.75,
"xanchor": "right",
"yanchor": "middle"
},
{
"source": "https://sdv.nyc3.cdn.digitaloceanspaces.com/assets/public/sha256/38/38728eaaf98d73d00363ee570601d64a4caa7fe2590fb0df5afb1b9129d6e20b.png",
"sizing": "contain",
"layer": "above",
"name": "sdvplot:axis:y:23",
"x": 0,
"y": 3,
"xref": "paper",
"yref": "y",
"sizex": 1,
"sizey": 0.75,
"xanchor": "right",
"yanchor": "middle"
},
{
"source": "https://sdv.nyc3.cdn.digitaloceanspaces.com/assets/public/sha256/b6/b623681ece167224ad4f51aef1ffa5a6f9e072af1cf1d6a6c158fd796e8d33ab.png",
"sizing": "contain",
"layer": "above",
"name": "sdvplot:axis:y:9",
"x": 0,
"y": 4,
"xref": "paper",
"yref": "y",
"sizex": 1,
"sizey": 0.75,
"xanchor": "right",
"yanchor": "middle"
}
]
}
}import { NBA_STANDINGS } from "@sportsdataverse/examples/data";
import { loadLeague } from "@sportsdataverse/sdvplot";
import { teamColorway, withAxisLogos } from "@sportsdataverse/sdvplot/plotly";
await loadLeague("nba");
// stats.nba.com's TeamName is the nickname ("Clippers"): sdvplot resolves it like an abbreviation.
const teams = NBA_STANDINGS.map((s) => s.team);
const figure = {
data: [
{
type: "bar",
orientation: "h",
y: teams,
x: NBA_STANDINGS.map((s) => s.wins),
marker: { color: teamColorway("nba", teams) },
},
],
layout: {
width: 560,
height: 360,
xaxis: { title: { text: "Wins (2023-24)" } },
// first place on top: a category axis runs bottom to top, so give it a descending range (categories are 0, 1, ...)
yaxis: { range: [teams.length - 0.5, -0.5] },
},
};
// On the y axis the logos sit left of the plot, one per category band; the tick labels are hidden, not blanked.
const logos = withAxisLogos(figure, "y", { league: "nba", height: 0.15 });
// In the browser: Plotly.newPlot(div, data, layout), as this page does. Without JavaScript the page shows the figure.
export const browser = {
lib: "plotly",
figure: logos,
label:
"The 2023-24 Pacific Division's wins, first place on top: the Clippers, Suns, Lakers, Kings and Warriors, each bar in its team's colour with its logo beside it",
} as const;
logos;
Tags: plotly · withAxisLogos · teamColorway · basketball · nba. All sdvplot examples.