Repository navigation
Description
A few suggested changes to default plotting parameters that I make in the majority of my plotting scripts. Of course these are just my personal preferences.
Discrete colormaps
The "cmap.discrete" parameter is currently true by default. I like the convenience of calling ax.pcolormesh(image, discrete=True) and think discrete colormaps can be very useful, but usually I just want the regular behavior of pcolormesh, which is to use a continuous colormap.
Grid lines
The "axes.grid" parameter is currently true by default. I think grid lines can be useful but can also be unnecessary or distracting; for example when plotting an image. Maybe I'm alone here.
Figure padding
Ultraplot figures have significant padding when labels are added to the axes. I think the default should be to have less padding; for example when making a figure for a paper in two-column format. I'm not sure which parameter this corresponds to. I tried changing "subplots.outerpad", but that cuts off the top part of plot.
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(3.0, 3.0), constrained_layout=True)
values = np.arange(16).reshape(4, 4)
ax.pcolormesh(values)
ax.set_xlabel("xlabel")
ax.set_ylabel("ylabel")
plt.savefig("test1.png", dpi=200)
import ultraplot as uplt
uplt.rc["grid"] = False
uplt.rc["cmap.discrete"] = False
uplt.rc["cmap.sequential"] = "viridis"
fig, ax = uplt.subplots(figsize=(3.0, 3.0))
ax.pcolormesh(values)
ax.format(xlabel="xlabel", ylabel="ylabel")
plt.savefig("test2.png", dpi=200)
uplt.rc["subplots.outerpad"] = 0.0
fig, ax = uplt.subplots(figsize=(3.0, 3.0))
ax.pcolormesh(values)
ax.format(xlabel="xlabel", ylabel="ylabel")
plt.savefig("test3.png", dpi=200)
matplotlib==3.9.2
ultraplot==1.0.3.post14
Activity
cvanelteren commentedon Jan 29, 2025
Hi there!
I am not too against changing the default standards that are currently there. However, I do feel like most of the issues you addressed could be fixed by a custom RC which falls out of scope for the direction of ultraplot.
That being said, I could be persuaded to make pcolormesh have continuous as default, but I am less in favor of the grid lines being turned off. I am also in favor for more compact plotting. I usually use
journal = "nat2"for controlling it -- not sure if this would solve your issue.Then again, I think this can also be controlled by an RC file. Would you be against using a custom RC over having to change these things explicitly?
austin-hoover commentedon Jan 30, 2025
I'm not against customizing with rc files; these are just my suggestions.
The third point could be some kind of bug, though. When I call
plt.show(), the figure padding looks great. The padding changes only for the output ofplt.savefig. Here is the difference:The first figure was saved using
plt.savefig(), and the second figure was saved usingplt.show()and hitting the save figure button in the popup window.cvanelteren commentedon Jan 30, 2025
I will have a look into the margins not being set correctly. If I vaguely recall there UltraPlot does act and change some things on draw; after the renderer is acquired.
You have made me think of potentially allowing a way for users to modify the default functions on import. That could potentially be a quality of life improvement without altering the main codebase. I will have a look at the style module and get back to you.
cvanelteren commentedon Jan 30, 2025
@austin-hoover you are right that it is controlled by outerpad. The related code is found https://github.com/Ultraplot/ultraplot/blob/e7bf24032ac1d33e4c72c5570584bf3e3a19288d/ultraplot/gridspec.py#L846.
I can also confirm there is a noticeable difference in the padding between the saved and shown image (e.g. in a repl). I can't recall if this was already an issue in proplot or this is somehow caused by changes on the mpl side, do you know by any chance? The savefig internally used for ultraplot/proplot merely wraps the existing method and seems not to modify the behavior
cvanelteren commentedon Jan 30, 2025
Update!
inserting a
figure.canvas.draw()in the savefig fixes the issue. Not sure what to do here. Any thoughts @beckermr?cvanelteren commentedon Jan 30, 2025
In particular, it would modify
savefigas:austin-hoover commentedon Jan 30, 2025
I don't think this issue showed up in proplot.
cvanelteren commentedon Jan 31, 2025
Margins are fixed and a new tag
1.04is available and can be updated from pip or conda. Will close for now as the remaining could be fixed with a local rc file. In addition, I think Ultraplot has plenty of tools to allow custom styling (see thestylemodule).However, if you do feel like these issues need addressing we could create a sub-issue to reopen this again.