![](/img/trans.png)
[英]Jupyter Notebook + Matplotlib; Freeze on plot.show()
[英]strange behavior with matplotlib plot.show
我想得到一個圖表,其中表示“父”產品的許多副產品。 我使用的代碼是下面的代碼,結果在附圖中。 如您所見,從產品值表示的末尾開始,一條直線開始連接下一個產品值的開頭
def drawData(self):
year = strftime('%Y')
nbr= len(product_list)
i = 0
lay = QtWidgets.QVBoxLayout(self.centralwidget)
lay.setContentsMargins(0, 0, 0, 30)
fig, ax = plt.subplots(figsize=(12, 6))
data1 = \[\]
lines1 = \[\]
tick = \[\]
nbrdate = 0
while i <= lungh -1:
name = productlist\[i\]
query = "SELECT ...AND name = '%s' " % (name)
nbr.execute(query)
search = nbr.fetchall()
for row in search:
d_data = str(row\['data'\])
month = d_data\[5:7\]
giorno = d_data\[8:\]
short = str(giorno + '.' + month)
data1.append(short)
value = row\['valore'\]
lines1.append(value)
if (nbrdate % 5 == 0):
tick.append(short)
nbrdate += 1
i += 1
line, = ax.plot(data1, lines1)
ax.set_xticks(tick)
ax.set(title='This is a title')
ax.grid()
self.plotWidget = FigureCanvas(fig)
lay.addWidget(self.plotWidget)][1]][1]
我解決了這個問題。 由於顯示問題,我通過將其替換為 QMainWindow 刪除了該圖層。 我將其值分配給每個名稱,從而獲得要傳遞給 plot 的各個行。 這可能不是技術上最合理的解決方案,但它確實有效
def drawData(self):
year = strftime('%Y')
nbr= len(product_list)
i = 0
nbrdate = 0
while i <= lungh -1:
name = productlist[i]
query = "SELECT ...AND name = '%s' " % (name)
nbr.execute(query)
search = nbr.fetchall()
data1 = []
values = []
tick = []
for row in search:
d_data = str(row['data'])
month = d_data[5:7]
giorno = d_data[8:]
short = str(giorno + '.' + month)
data1.append(short)
value = row['valore']
values.append(value)
if (nbrdate % 5 == 0):
tick.append(short)
nbrdate += 1
if nome == 'AAAA':
line1 = values
legend1 = 'AAAA'
if nome == 'BBBB':
line2 = values
legend2 = 'BBBB'
...
i += 1
fig, ax = plt.subplots(figsize=(12, 6))
line = ax.plot(data1, line1)
line = ax.plot(data1, line2)
...
ax.set_xticks(tick)
ax.set(title='This is a title')
ax.grid()
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.