python - 使用 matplotlib.animation 扭曲刻度标签
问题描述
随着 matplotlib 的更新版本,我在动画图上得到了扭曲的标签。有其他人得到这个吗?难道我做错了什么?
最小工作示例:
from netCDF4 import Dataset
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from IPython import display
print(matplotlib.__version__)
# Make a random array of data to plot
r = np.random.rand(10,100,100)
fig, ax = plt.subplots(1,1,figsize=(10,10))
# Initiate Plot
plot = ax.pcolormesh(range(0,100),
range(0,100),
r[0],
cmap='RdBu')
cb = fig.colorbar(plot)
cb.set_label('Temperature')
def animate(frame):
C = r[frame][:-1,:-1]
plot.set_array(C)
ani = animation.FuncAnimation(fig,
animate,
frames= range(0,r.shape[0]),
)
video = ani.to_html5_video()
html = display.HTML(video)
display.display(html)
plt.close()
我的标签似乎被放置了很多次(尽管即使动画只有两帧,这个错误仍然存在),它们看起来像这样:
如果我注释掉下面的所有行,则不会发生此行为,ax.pcolormesh...
这会创建看起来不错的静态图。
我在 matplotlib 3.3.2
解决方案
推荐阅读
- cgal - Pointcloud to Model with CGAL 完整的初学者,教程?指南或提示?
- spring - 使用带有 StepVerifier 的 webTestClient 的 Spring REST 文档(反应式端点)
- forms - Xamarin 表单列表视图中的 TapGestureRecognition
- intellij-idea - 如何控制 (Java) lambdas 的 IntelliJ Idea 自动格式化括号位置?
- c# - 在统一独立构建中获取构建日期
- c# - 从 C# 使用时 F# 记录类型的相等性
- c# - 实体框架 - 在包含后使用 where() 过滤行
- firebase - Flutter Firebase Crashlytics 将堆栈跟踪报告为 Java 类文件而不是 Dart 文件
- node.js - 当 NPM 出现故障时,有什么方法可以避免停机?(在这种情况下与 GC App Engine 部署有关)
- django - Django 连接到 IBM Cloud 数据库