How to set the figure alignment in OJS? #13527
-
DescriptionI would like to centre a figure generated using OJS. Here is an MWE: ---
format:
revealjs:
embed-resources: true
---
## {.smaller .c-centre}
```{python}
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
np.random.seed(42)
x = np.random.randint(0, 100, size=100)
m = 3
c = 2
y = (m * x + c) + np.random.normal(0, 40, size=100)
ojs_define(data = {
"x": x.tolist(),
"y": y.tolist()
})
```
```{ojs}
//| fig-align: center
//| fig-width: 100%
viewof m = Inputs.range([-10, 10], {step: 0.5, label: "m", width: "10em"})
viewof c = Inputs.range([-100, 100], {step: 1, label: "c", width: "10em"})
line = data.x.map(x => ({x: x, y: m * x + c}))
Plot.plot({
x: {axis: null, domain: [0, 100]},
y: {axis: null, domain: [-100, 300]},
marks: [
Plot.frame(),
Plot.dot(transpose(data), {x: "x", y: "y", fill: "blue"}),
Plot.line(line, {x: "x", y: "y", stroke: "red"})
]
})
``` The figure is still left aligned. I addition, I'd also like to be able to set the figure width. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
"figure" are cross-referenceable object, otherwise it's an "image". Here you need to understand the structure of the HTML code your are building. You can do so using your favourite browser and its inspect/developer mode. I suggest searching for the issues/discussions on the topics (there are several treating this and showing solutions and workarounds). Finally, but related, the width of something in HTML especially when using relative units such as percentages, mean relative to the parent div, not relative to the viewscreen. |
Beta Was this translation helpful? Give feedback.
"figure" are cross-referenceable object, otherwise it's an "image".
Note also that in this particular case, it's not even an image (png/svg), it's a widget involving an image.
Here you need to understand the structure of the HTML code your are building. You can do so using your favourite browser and its inspect/developer mode.
I suggest searching for the issues/discussions on the topics (there are several treating this and showing solutions and workarounds).
Finally, but related, the width of something in HTML especially when using relative units such as percentages, mean relative to the parent div, not relative to the viewscreen.
This being said, You can look at the documentation of the …