【发布时间】:2018-02-16 14:24:24
【问题描述】:
我想从以下格式的字典中绘制选择数据:
dictdata = {key_A: [(1,2),(1,3)]; key_B: [(3,2),(2,3)]; key_C: [(4,2),(1,4)]}
我正在使用以下函数来提取与特定键对应的数据,然后将 x 和 y 值分成两个可以绘制的列表。
def plot_dictdata(ax1, key):
data = list()
data.append(dictdata[key])
for list_of_points in data:
for point in list_of_points:
x = point[0]
y = point[1]
ax1.scatter(x,y)
我希望能够多次调用此函数(请参见下面的代码)并使所有相关数据集出现在同一个图表上。但是,最终图只显示了最后一组数据。如何在不清除前一组数据的情况下在同一张图上绘制所有数据集?
fig, ax1 = plt.subplots()
plot_dictdata(ax1, "key_A")
plot_dictdata(ax1, "key_B")
plot_dictdata(ax1, "key_C")
plt.show()
我才刚刚开始使用 matplotlib,并且无法使用以下讨论相关问题的示例找出解决方案。先感谢您。 how to add a plot on top of another plot in matplotlib? How to draw multiple line graph by using matplotlib in Python Plotting a continuous stream of data with MatPlotLib
【问题讨论】:
标签: python-2.7 matplotlib