Matplotlib打开但没有响应

时间:2018-07-30 14:17:24

标签: python-3.x matplotlib conda

我在下面有一个绘图功能。它已经成功地在miniconda上运行,但是今天早上我不得不卸载并重新安装miniconda。然后,我安装了必要的库。 PyQt5可以正常工作,但是当我用一个按钮调用此函数时,绘图窗口会打开但没有响应。

我什至在普通的Python(不是miniconda)上尝试了相同的代码,并且发生了相同的结果。

我的编辑是Geany和Pyzo。

我添加了plt.ion,但没有成功。

我的图书馆

Python 3.6.5

matplotlib 2.2.2 py36h153e9ff_1

pyqt 5.9.2 py36h1aa27d4_0

conda 4.5.8 py36_0

我编辑了我的代码。这是可行的,但是无法通过按钮调用它。

#!/usr/bin/env python3
#-*- coding:utf-8 -*-
# vim:fileencoding=utf-8

import matplotlib.pyplot as plt
import matplotlib

def PlotDistanceToHome():
    """ Plot Distance To Home (m) """
    TimeMin = [1,2,3,4,5,6,7,8,9,10]
    DistanceToHome = [1,2,3,4,5,6,7,8,9,10]
    PlotFunction(TimeMin,
                        'Zaman (dk)',
                        [DistanceToHome],
                        ['ko:'],
                        ['Eve Mesafe (m)'],
                        None,
                        None,
                        False)

def PlotFunction(xdata, xlabel, y1data, y1specs, y1label, y2data, y2label, Y2Axis):
    """
    Plot Function for LOG Data
    xdata = self.TimeMin
    xlabel = 'Zaman (dk)'
    y1data can be anything such as AGL list, Voltage etc.
    y1specs includes linecolor and linetype (dashed, dotted etc.)
    y1label for legends
    y2data is flight mode, current or something else
    y2label for legends
    Y2Axis is boolean if Y2Axis is exists.
    """
    matplotlib.rcParams.update({'font.size': 18})

    fig = plt.figure()
    fig.set_size_inches(9,6.75, forward=True) # 4:3

    # Sub-Plot 1
    ax1 = fig.add_subplot(111)

    # Axes 1 - Y1Data
    Lines = []
    for i in range(len(y1data)):
        temp = ax1.plot(xdata, y1data[i], y1specs[i], linewidth=3, label=y1label[i])
        Lines += temp
    ax1.set_xlabel(xlabel)
    #ax1.set_ylabel(y1label)

    # Axes 2 - Flight Mode
    if Y2Axis == True:
        ax2 = ax1.twinx()
        #ax2.set_ylabel(y2label)
        line4 = ax2.plot(xdata, y2data, label=y2label, 
                        color='#fb7d07',
                        linestyle='dotted',
                        marker='o',
                        markeredgecolor='#fb7d07',
                        markerfacecolor='#fb7d07',
                        markersize=4) # Color: Pumpkin Orange
        if y2data == CSV['ucus_modu']:
            FlightMode = ['YERDE', 'KALKIS', 'AYRILMA', 'SEYIR', 'KONUM', 'DONUS', 'INIS']
            ax2.set_yticklabels(FlightMode)
        Lines += line4

    # Set Legends
    labels = [l.get_label() for l in Lines]
    ax1.legend(Lines, labels, ncol = len(labels), loc='upper center', bbox_to_anchor=(0.5, 1.15))

    # Show Plot
    plt.grid(True)
    plt.show()

PlotDistanceToHome()

0 个答案:

没有答案