【发布时间】:2014-06-26 01:07:12
【问题描述】:
如何使用 matplotlib 使第一张图片看起来像第二张?
蓝色图表中的每个“列”都代表类似于相应绿色图表“列”的倒数。我认为这种格式提供了丰富的信息。
编辑: 这段代码应该让您了解我在做什么。
import tkinter as tk
import numpy as np
from matplotlib.figure import Figure
from matplotlib.font_manager import FontProperties
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
infoFrame = tk.Frame(tk.Tk(), width=1200, height=750, padx=5, pady=5)
infoFrame.grid()
graphCanvas = tk.Canvas(infoFrame)
graphCanvas.grid(columnspan=5, rowspan=2, row=1)
infoGraph = Figure(figsize=(7, 6), dpi=100)
firstGraph = infoGraph.add_subplot(2, 1, 2, axisbg="#9DDEFF")
secondGraph = infoGraph.add_subplot(2, 1, 1, axisbg="#B2F0B2")
entries = ["one", "two"]
types = ["x", "y"]
_tkColors = ["black", "yellow", "magenta", "cyan", "red", "green", "blue"]
index = np.arange(len(types))
width = 0.3
firstLabelData = []
secondLabelData = []
iterator = 0
barData = {'interval': 1, 'data':
{'one': {'std': [0.0, 0.0], 'sum': [5, 4], 'mean': [5.0, 4.0]},
'two': {'std': [0.0, 0.0], 'sum': [14, 2], 'mean': [14.0, 2.0]}}}
for entry in entries:
firstPlot = firstGraph.bar(index+(width*iterator), barData["data"][entry]["sum"], width,
color=_tkColors[iterator % len(_tkColors)], yerr=barData["data"][entry]["std"])
secondPlot = secondGraph.bar(index+(width*iterator), barData["data"][entry]["sum"], width,
color=_tkColors[iterator % len(_tkColors)], yerr=barData["data"][entry]["std"])
firstLabelData.append(firstPlot[0])
secondLabelData.append(secondPlot[0])
iterator += 1
firstGraph.text(3.6, 18, "Inverse Graph 1", weight="bold")
firstGraph.set_xlabel("Over " + str(30) + " Iterations")
firstGraph.invert_yaxis()
secondGraph.text(3.5, 18, "Graph 1", weight="bold")
fontP = FontProperties()
fontP.set_size("small")
secondGraph.legend(tuple(firstLabelData), tuple(entries), prop=fontP, loc=2)
graph = FigureCanvasTkAgg(infoGraph, master=graphCanvas)
graph.show()
graph._tkcanvas.pack(side=tk.TOP, expand=1)
infoFrame.mainloop()
【问题讨论】:
-
蓝色图中的每个“列”代表类似于相应绿色图“列”的倒数。我认为这种格式提供了丰富的信息。
-
您应该包含一些您尝试过的最小可运行代码(包括一些合成数据)。我会使用
axvspan来获取颜色,然后使用top和bottomkwargs 调用bar。 -
~您没有发布 相关 代码。~ nm,SO 位以不同的速率刷新
-
它现在已经走得太远了,因为没有人会阅读那么多代码。 (我们在这里就像金发姑娘;))
-
很好。我会想办法的!
标签: python python-3.x matplotlib