To create a dark-themed animation, you must configure matplotlib.rcParams to set the figure, axes, and savefig facecolors to your desired dark color (e.g., #001219) and remove the axes spines. Additionally, ensure all text elements (labels, titles, legends, ticks) are explicitly set to a light color like 'w' (white) using the plot's setter methods.
import matplotlib as mpl
import pynimate as nim
# 1. Setup Matplotlib dark theme
for side in ["left", "right", "top", "bottom"]:
mpl.rcParams[f"axes.spines.{side}"] = False
mpl.rcParams["figure.facecolor"] = "#001219"
mpl.rcParams["axes.facecolor"] = "#001219"
mpl.rcParams["savefig.facecolor"] = "#001219"
# 2. Prepare Data
df = pd.read_csv("data.csv").set_index("time")
dfr = nim.LineDatafier(df, "%Y-%m-%d", "12h")
# 3. Define post_update callback
def post(self, i):
self.ax.yaxis.set_major_formatter(tick.FuncFormatter(lambda x, pos: human_readable(x)))
# 4. Initialize Plot
plot = nim.Lineplot(
dfr,
post_update=post,
palettes=["Set3"],
scatter_markers=False,
legend=True,
fixed_ylim=True,
grid=False,
)
# 5. Apply styling for dark mode
plot.set_title("Title", color="w")
plot.set_xlabel("xlabel", color="w")
plot.set_time(callback=lambda i, datafier: ..., color="w")
plot.set_legend(labelcolor="w")
plot.set_xticks(colors="w")
plot.set_yticks(colors="w")
# 6. Animate
cnv = nim.Canvas()
cnv.add_plot(plot)
cnv.animate()