Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions content/develop/api-reference/charts/pyplot.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ description: st.pyplot displays a matplotlib.pyplot figure.
<Autofunction function="streamlit.pyplot" />

<Warning>
Matplotlib [doesn't work well with threads](https://matplotlib.org/3.3.2/faq/howto_faq.html#working-with-threads). So if you're using Matplotlib you should wrap your code with locks as shown in the snippet below. This Matplotlib bug is more prominent when you deploy and share your app apps since you're more likely to get concurrent users then.
Matplotlib [doesn't work well with threads](https://matplotlib.org/3.3.2/faq/howto_faq.html#working-with-threads). So if you're using Matplotlib you should wrap your code with locks. This Matplotlib bug is more prominent when you deploy and share your apps because you're more likely to get concurrent users then. The following example uses [`Rlock`](https://docs.python.org/3/library/threading.html#rlock-objects) from the `threading` module.

```python
from matplotlib.backends.backend_agg import RendererAgg
_lock = RendererAgg.lock
import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
from threading import RLock

_lock = RLock()

x = np.random.normal(1, 1, 100)
y = np.random.normal(1, 1, 100)

with _lock:
fig.title('This is a figure)')
fig.plot([1,20,3,40])
fig, ax = plt.subplots()
ax.scatter(x, y)
st.pyplot(fig)
```

Expand Down