Skip to content

Pcolormesh: Artifacts compared to pure Matplotlib? #136

Closed

Description

@Ockenfuss

When plotting with pcolormesh using ultraplot, I see fine artifacts in the result (this script will produce a large figure):

import matplotlib.pyplot as plt
import ultraplot as uplt
import numpy as np
fig, ax=uplt.subplots(figwidth="20cm", dpi=600)
arr=np.random.rand(1000,1000)
x=np.linspace(0, 1, 1000)
ax.pcolormesh(x,x,arr, cmap='plasma', discrete=False)

Image

With pure matplotlib, on my system, I get the correct result:

import matplotlib.pyplot as plt
import numpy as np
fig, ax=plt.subplots(figsize=(10,10), dpi=600)
arr=np.random.rand(1000,1000)
x=np.linspace(0, 1, 1000)
ax.pcolormesh(x,x,arr, cmap='plasma')

Image

Activity

  1. cvanelteren commented on Apr 2, 2025

    @cvanelteren
    Collaborator

    I see two artefacts in this plot, which one are you referring to specifically?

  2. cvanelteren commented on Apr 3, 2025

    @cvanelteren
    Collaborator

    For context, in the source i can see that there is an edgefix applies particularly to pcolormesh which is don't fully comprehend why this is. Maybe it's related. I will have time to look into this after next week. PR is always welcome!

  3. Ockenfuss commented on Apr 3, 2025

    @Ockenfuss
    Author

    I meant the fact that the pixels are not square in the ultraplot case. Now, I realize that also on the left side near the black axis line, the pixels seem to be cut. What else do you see? And, most important: Can you reproduce this? I used a clean environement with only ultraplot, numpy, jupyter and matplotlib.

  4. Ockenfuss commented on Apr 3, 2025

    @Ockenfuss
    Author

    I am not familiar with the ultraplot codebase, but I will see if I find some time over the weekend to track this down further!

  5. cvanelteren commented on Apr 3, 2025

    @cvanelteren
    Collaborator

    I see that the edges of the squares are the same colour as the inside of the square creating a round illusion. Furthermore the black bar is still visible as if it is on top of the axes.

  6. cvanelteren commented on Apr 3, 2025

    @cvanelteren
    Collaborator

    The first is related to the issue I mentioned above. The second dunno.

  7. cvanelteren commented on Apr 3, 2025

    @cvanelteren
    Collaborator

    Ah wait it's the grid major. That's what I am seeing.

  8. Ockenfuss commented on Apr 3, 2025

    @Ockenfuss
    Author

    Yes, the black line is just the grid. I experimented a little and found that the issue with the squares vanishes if I set "edgefix=False".

  9. cvanelteren commented on Apr 3, 2025

    @cvanelteren
    Collaborator

    Yes, this is the issue I mentioned earlier. When going through the code I didn't really understand why this part is in there. I don't have access to a computer at the moment so will need to judge if this can be removed as it was an issue on older versions. I don't use pcolormesh too often and rely on imshow more so perhaps this occurs with non regular meshes?

  10. Ockenfuss commented on Apr 3, 2025

    @Ockenfuss
    Author

    Ha, then thank you even more for the quick answers! It seems I am not the first one to discover this artifact: proplot-dev/proplot#455

  11. cvanelteren commented on Apr 3, 2025

    @cvanelteren
    Collaborator

    There is a function (perhaps private) that "fixes" the edges that is called on quad meshes (of which pcolormesh is one). I can't recall exactly why this function exists. I would need to have some coffee and a computer to evaluate the existence of this function.

  12. cvanelteren commented on Apr 6, 2025

    @cvanelteren
    Collaborator

    Ok had a look at this. The reason seems to be given in the docs https://ultraplot.readthedocs.io/en/latest/api/ultraplot.axes.PlotAxes.html#ultraplot.axes.PlotAxes.pcolormesh. There is an issue with non-pdf and svg exports with mpl that produces visual artifacts, see https://github.com/jklymak/contourfIssues. As ultraplot by default exports to pdf (without giving an extension directly) it is turned on by default.

    Not really happy with this behavior, and more leaning towards having it off and then turning it on when exporting the file to another format, however this may be a bit tricky to implement as the plot was already generated. Will have a closer look.

  13. cvanelteren commented on Apr 7, 2025

    @cvanelteren
    Collaborator

    Ok so I am a bit of two minds on this. On the one end, this artifact is not wanted when you are doing some exploratory data analysis. On the other end the issue generated through visual artifacts is fixed by ultraplot but is not caused by matplotlib or ultraplot but by a potential pdf viewer. In both cases, I am leaning towards turning this feature off by default and only turn it on when explicitly set. What do you think @Ockenfuss?

  14. cvanelteren commented on Apr 7, 2025

    @cvanelteren
    Collaborator

    Actually, I don't think this a good idea. See #147 for motivation. Closing this issue, the artifacts can be suppressed in EDA context with the parameter edgefix = False or setting ultraplot.rc["edgefix"] = False.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions