-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plotting of fine grained meshes is sub-optimal because of edge drawing #203
Comments
Since you mention it's a better example, maybe you could post the pictures for the file nonetheless? Having the MWE is helpful, but those pictures probably clarify it. I atleast have trouble seeing what the problem exactly is in these pictures. Also, what's the question/issue exactly? Do you suggest a different default? |
@Huite the mwe and figure are now also added to the issue description for the other example. Unfortunately none of the alternatives result in a perfect plot. Furthermore, I think this is actually a matplotlib issue, but since most matplotlib applications do not draw these tiny polygons I guess we are the only ones that are affected by it. |
So in essence: you either have too small polygons, or too thick lines. You want the lines to fill up the holes between the polygons, but not so much that it smears everything. The easiest way to achieve this seems to fiddle with the linewidths parameter. It's a bit hard to find what linewidths means exactly, but apparently it's points: Where 1 point is 0.353 mm or 1/72 of an inch: https://en.wikipedia.org/wiki/Point_(typography) fig, ax = plt.subplots(figsize=(7, 7), dpi=300)
uds_sel.mesh2d_s1.ugrid.plot(vmin=vmin, vmax=vmax, linewidths=0.1) At 300 dpi, 0.1 is not quite enough; if you zoom in: But 0.3 seems to do the trick: 0.3 seems to work fairly well across the board here, also at the default 100 dpi: Total extent is about 200 km in the y direction, with 7 inches times 72 is 514 points. A single point is then approximately 400 m on the map. So we'd expect the rivers to be buffered 200 m at both sides, increasing the total width by ~400 m. This analysis doesn't help that much though, because I wouldn't know how to compute the widths of the gaps in the North sea between the polygons... So probably best to fiddle with the linewidths: get them a small as possible, without the gaps appearing. |
Thanks for these efforts. However, it is a bit cumbersome to fiddle with linewidths, since they will differ for each model output file and zoom level right? For instance in the adh_san_diego plot this still gives white lines with linewidth=0.3. |
I agree, but it's a somewhat workable solution for now. I tried switching to other backends, but the white lines are drawn consistently. It's a matplotlib issue, so you could try raising an issue there, or ask on the matplotlib discourse forum first: It might be partly a stylistic choice. I think I recall seeing it on other patches as well, so I'm not entirely sure it's just the PolyCollection, it could be all patches. I don't have my hopes up that they'll be eager to change this though, I reckon it has been like this forever. As you mentioned, it's partly caused by having so many small elements, which is apparently triggering it. This also means it's a little slow at drawing the plot: I'm pretty sure it's looping over every polygon while rasterizing to pixels. It's been on my list to add some datashader trimesh support: https://datashader.org/user_guide/Trimesh.html |
From matplotlib: here's a good explanation matplotlib/matplotlib#9574 (comment)
|
See also: https://github.com/jklymak/contourfIssues This mentions:
Which matches my observation of a value of ~0.3. What we could do, is simply set |
We should also make a note in the plotting docs. |
When plotting a ugrid with large resolution, sometimes narrow branches with fine cells are drawn too wide because the edges are drawn. I have created a minimal reproducible example with one of the datasets included in xugrid:
This is not the best example. However, it is clear that the empty area between cells is wider in some cases than in others. The lower-left example shows the most whitespace but also has white edges all over the grid:
A better example would be with:
The text was updated successfully, but these errors were encountered: