Open Viech opened 2 years ago
Here is a simpler example that I think is related to the problem.
The image shown on the Notebook and the exported .png
versions are perfectly crisp.
However, the .svg
and .pdf
versions are heavily blurry (antialiasing filter?).
I tried both with the orca
and the kaleido
engines; the problem is the same.
import plotly.express as px
fig = px.imshow([[0, 1], [2, 3]])
fig.write_image("heatmap.pdf")
fig.show()
Versions:
MacOS 13.4.1
python 3.10.12
plotly 5.15.0
plotly-orca 4.1.4
python-kaleido 0.2.1
I am facing similar issues, when saving heat map plotted using px.imshow as png, the figure is alright but when saving it as pdf the heatmap is blurred (not the text).
Version: macOS 13.2 Python 3.11.5 plotly 5.9.0 kaleido 0.2.1
As png:
As pdf:
I also encountered the same problem. Is there any follow-up on this issue?
Thanks for your interest in Kaleido. We are currently working on an overhaul that might address your issue - we hope to have news in a few weeks and will post an update then. Thanks - @gvwilson
I have a relatively large matrix that I want to plot using
graph_objects.Heatmap
. The matrix has some structure that should become immediately apparent to the viewer (i.e. it has a constant diagonal and is symmetric). However due to visual artifacts, it looks like these properties are violated in the image produced bywrite_image
(with thekaleido
backend, haven't testedorca
).It was difficult to write a simple example script to reproduce these distortions, as variations in both the matrix and output image size can affect the issue significantly (both in intensity and quality). In any case it looks to be an aliasing artifact related to the selection of heatmap cell data that results in a non-bijective map between the heatmap cells and regions within the (vector) output image.
In the script below, one output format is PDF to rule out image compression as a culprit (as there the heatmap appears to be stored as a vector image as its cells remain sharp when zoomed in). However, the issue can be reproduced also when the output format is PNG. I assume that in the vector-output case, the heatmap data is (badly) rescaled like a bitmap image whose pixels are then re-interpreted as an array of square cells, even though those cells then do not match the heatmap/data cells any more.
The outcomes are:
PDF: n=200_400x400.pdf n=400_400x400.pdf
PNG (note in the first image that only the heatmap, not the text looks blurred):
![n=400_400x400](https://user-images.githubusercontent.com/3780206/150566889-e875f21b-7cc8-4f17-9cd2-e0e6903eec1c.png)
Given that my understanding of the problem is correct, I would suggest: