fig-width has no effect in a quarto document

Question:

Consider the following code:

---
title: "Untitled"
format: pdf
---

```{python}
#| echo: false
#| fig-align: center
#| fig-width: 1cm

import matplotlib.pyplot as plt

x = [1, 2]
y = [2, 3]

plt.plot(x,y)
```

The parameter fig-width has no effect whatever the chosen width.

Could someone please help me?

Asked By: PaulS

||

Answers:

Edit

You can also use set_figwidth from matplotlib to control the plot figure sizes generated by matplotlib.

---
title: "Untitled"
format: pdf
engine: jupyter
---

```{python}
#| echo: false
#| fig-align: center

import matplotlib.pyplot as plt

plot = plt.figure()
plot.set_figwidth(2)
plot.set_figheight(3)

x = [1, 2]
y = [2, 3]

plt.plot(x,y)

```

plot sized with matplotlib options


Try with integer number 2 instead of 2cm. (It works when with engine: knitr)

---
title: "Untitled"
format: pdf
engine: knitr
---

```{python}
#| echo: false
#| fig-align: center
#| fig-width: 2


import matplotlib.pyplot as plt

x = [1, 2]
y = [2, 3]

plt.plot(x,y)

```
Answered By: shafee
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.