给定一个 matplotlib.axes_subplots.AexesSubplot 对象,我如何判断它包含什么类型的绘图?是否有 matplotlib 功能可以为我确定这一点?例如……
我通常用 pandas 绘制数据
import pandas as pd
df = pd.DataFrame({'y':range(10)})
line_ax = df.plot()
或
bar_ax = df.plot(kind='bar')
或
barh_ax = df.plot(kind='barh')
请您参考如下方法:
matplotlib 轴不关心它包含哪个图,甚至不知道它。
问题还在于如何区分“种类”的情节。包含 2 个条、多个标记、2 条线和 3 个箭头的轴中的图是什么样的?
pandas plot 函数的 kind 参数只是一个标志,pandas 通过它来决定调用哪个绘图函数。这与轴无关,您当然也可以在同一轴上使用 kind='bar' 和 kind='scatter' 生成的图。
所以答案是:不,没有确定轴中图类型的通用方法,主要是因为没有“图类型”这样的东西。
当然,根据您需要此类信息的目的,可能有其他方法可以满足您的需求。
