Matplotlib plots are blurry when using a large figsize
See original GitHub issueFor example:
import streamlit as st
import numpy as np
import pandas as pd
np.random.seed(0)
df = pd.DataFrame(np.random.normal(1, 1, size=100))
df.plot(figsize=(25, 5))
st.pyplot()
Results in this unreadable image:
We currently clamp st.pyplot
images to Streamlit’s MAXIMUM_CONTENT_WIDTH
; images bigger than this get downscaled.
See pyplot.marshall()
:
image_proto.marshall_images(
image, None, -2, new_element_proto.imgs, False, channels="RGB", format="PNG"
)
That -2
value is a magic number that causes marshall_images
to do the clamping/downscaling. We could consider either passing a value of 0
(which would not do any downscaling), or we could warn the user if their image is much bigger than MAXIMUM_CONTENT_WIDTH.
Also, we should definitely turn these magic width
values into constants:
ORIGINAL_WIDTH = 0
CLAMP_TO_MAX_CONTENT_WIDTH = -1
(or whatever.)
This issue was originally raised in the Streamlit forums, here: https://discuss.streamlit.io/t/matplotlib-plots-are-blurry/1224
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:5 (1 by maintainers)
Top Results From Across the Web
2 ways to improve the default resolution of matplotlib plots ...
Solution 1. Change the default dpi settings in matplotlib. By default the plots rendered in our notebooks are png format with a relatively...
Read more >Matplotlib plots are blurry - Using Streamlit
An easy fix is to pass a small figsize. (Each inch in figsize is ~1000 pixels, so a figsize of (15, 3) will...
Read more >inline images have low quality - matplotlib - Stack Overflow
I've tried using matplotlib's plt. imshow() as well, which has the exact same result. I'm starting the notebook with ipython notebook --pylab ...
Read more >How do you improve Matplotlib image quality? - Tutorialspoint
Set the figure size and adjust the padding between and around the subplots. · Make a 2D data raster using a np.array. ·...
Read more >How to Change Plot and Figure Size in Matplotlib - Datagy
One of the simplest and most expressive ways of changing the plot size in Matplotlib is to use the figsize= argument. As the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Since this was posted 1.5 years ago (😱), we added some arguments to
st.image
to give developers more control. Taking that work as inspiration, I think the best solution here would be to give developers the same level of control forst.pyplot
as we provide forst.image
. In fact, we should support the exact same resolution-related parameters forpyplot
as forimage
.This means
st.pyplot
would take the following parameters:In addition, we should explicitly document the fact that you can pass
dpi=[some number]
tost.pyplot()
to change the pixel density. (This is automatically supported today becausest.plot()
forwards itskwargs
to Matplotlib’sFigure.savefig()
(see docs)IMPORTANT: When doing this we should make sure to not change the default behavior of
st.pyplot
!I’ve found that in my plots I can change the resolution by increasing the figsize, but the fig always spans the entire width of the page. Is there a way to turn off the auto scaling for pyplot?