0
为了各种信息与同步的x轴(时间轴,numpy.datetime64
)结合我已经写了下面的例子:Matplotlib,同步散射 - ,violin-之间时间轴和箱线图
import numpy as np
import matplotlib.pyplot as plt
x_axis = [np.datetime64("2016-01-01"), np.datetime64("2016-02-01")]
y_data = [3, 5]
fig = plt.figure()
ax1 = fig.add_subplot(311)
ax2 = fig.add_subplot(312, sharex=ax1)
ax3 = fig.add_subplot(313, sharex=ax1)
# Plot the scatter plot
ax1.scatter(x_axis, y_data)
# Now draw the violinplot and the boxplot
for (timestamp, y) in zip(x_axis, y_data):
data = np.random.rand(100) + y
ax2.violinplot(data,
positions=[timestamp],
widths=[np.timedelta64(500000, 's')])
# ax3.boxplot(data,
# positions=[timestamp],
# widths=[np.timedelta64(10, 's')])
问题现在是第三个(注释)部分:当定义位置和withs以正确的单位时,一切正常,因此散点图可以绘制在时间轴上,但boxplot在绘制晶须时会失败。我收到一个TypeError: ufunc multiply cannot use operands with types dtype('float64') and dtype('<M8[D]')
。
有没有什么方法可以在实时轴上正确绘制箱形图,以便同步按需要工作?
PS:注意,宽度都在单位秒,如果时间单位是太大,violinplot不顺畅任何更多...
我试图使用seaborn,但获得时间轴的正常工作并不像预期的那样真正工作,特别是在尝试与其他matplotlib数字同步轴时。 – Sosel