小编Ava*_*ris的帖子

matplotlib中的散点图

这是我的第一个matplotlib程序,对不起我的无知.

我有两个字符串数组.说,A = ['test1','test2']B = ['test3','test4'].如果AB元素之间存在任何相关性,则其corr值将设置为1.

        test1 | test2
test3 |   1   |   0

test4 |   0   |   1
Run Code Online (Sandbox Code Playgroud)

现在,我想绘制一个散点图,其中我的X轴将是元素A,Y轴将是元素,B如果相关值是1,则它将在散射图中标记.怎么做?

python matplotlib scatter-plot

24
推荐指数
1
解决办法
15万
查看次数

如何使用Python和matplotlib制作一个4d图

我正在寻找一种使用Python和matplotlib创建四维图(表面加上色标)的方法.我能够使用前三个变量生成曲面,但我没有成功添加第四个变量的颜色标度.以下是我的数据的一小部分.任何帮助将不胜感激.谢谢

数据子集

var1    var2    var3    var4
10.39   73.32   2.02    28.26
11.13   68.71   1.86    27.83
12.71   74.27   1.89    28.26
11.46   91.06   1.63    28.26
11.72   85.38   1.51    28.26
13.39   78.68   1.89    28.26
13.02   68.02   2.01    28.26
12.08   64.37   2.18    28.26
11.58   60.71   2.28    28.26
8.94    65.67   1.92    27.04
11.61   59.57   2.32    27.52
19.06   74.49   1.69    63.35
17.52   73.62   1.73    63.51
19.52   71.52   1.79    63.51
18.76   67.55   1.86    63.51
19.84   53.34   2.3     63.51
20.19   59.82   1.97    63.51
17.43   57.89   2.05    63.38
17.9    59.95 …
Run Code Online (Sandbox Code Playgroud)

python plot matplotlib

14
推荐指数
1
解决办法
1万
查看次数

lxml etree.iterparse错误"TypeError:读取文件对象必须返回纯字符串"

我想使用lxml解析HTML文档.我正在使用python 3.2.3和lxml 2.3.4(http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml)

我正在使用etree.iterparse解析文档,但它返回以下运行时错误:

Traceback (most recent call last):
  File "D:\Eclipse Projects\Python workspace\Crawler\crawler.py", line 12, in <module>
    for event, elements in etree.iterparse(some_file_like):
  File "iterparse.pxi", line 491, in lxml.etree.iterparse.__next__ (src/lxml\lxml.etree.c:98565)
  File "iterparse.pxi", line 512, in lxml.etree.iterparse._read_more_events (src/lxml\lxml.etree.c:98768)
TypeError: reading file objects must return plain strings
Run Code Online (Sandbox Code Playgroud)

问题是:如何解决这个运行时错误?

非常感谢你.

这是代码:

from io import StringIO
from lxml import etree

some_file_like = StringIO("<root><a>data</a></root>")

for event, elements in etree.iterparse(some_file_like): #<-- Run-time error happens here
    print("%s, %4s, %s" % (event, elements.tag, elements.text))
Run Code Online (Sandbox Code Playgroud)

python lxml elementtree iterparse

10
推荐指数
1
解决办法
4740
查看次数

为什么Python的Decimal函数默认为54个位置?

输入后

from decimal import *
getcontext().prec = 6
Decimal (1) / Decimal (7)
Run Code Online (Sandbox Code Playgroud)

我得到了价值

Decimal('0.142857')  
Run Code Online (Sandbox Code Playgroud)

但是,如果我进入Decimal (1.0/7)我得到

Decimal('0.142857142857142849212692681248881854116916656494140625')
Run Code Online (Sandbox Code Playgroud)

python decimal

6
推荐指数
1
解决办法
178
查看次数

PyQT将lambda函数连接到Signal

我遇到了以下问题.我正在尝试将lambda函数连接到Signal以最终传递一些额外的数据.

def createTimeComboBox(self,slotCopy):
    timeComboBox = QComboBox()

    #...

    cmd = lambda func=self.test:func()
    self.connect(timeComboBox, SIGNAL("currentIndexChanged(int)"),cmd)

#...

def test(self, value):
    print value
Run Code Online (Sandbox Code Playgroud)

当我运行时,createTimeComboBox(),我收到此错误:

TypeError: 'int' object is not callable
Run Code Online (Sandbox Code Playgroud)

更改

self.connect(timeComboBox, SIGNAL("currentIndexChanged(int)"),cmd)
Run Code Online (Sandbox Code Playgroud)

self.connect(timeComboBox, SIGNAL("currentIndexChanged(int)"),self.test)
Run Code Online (Sandbox Code Playgroud)

工作正常,但我希望能够传递slotCopy变量,所以假设我需要使用该lambda方法.

我曾与一个以前做过QPushButtonclicked()信号,并能正常工作.

def createToDoctorButton(self,extraData):
    toDoctorButton = QPushButton()

    cmd = lambda func=self.goToDoctor:func(extraData)
    self.connect(toDoctorButton,  SIGNAL('clicked()'),cmd)

    return toDoctorButton

def goToDoctor(self,extraData):
    print extraData
Run Code Online (Sandbox Code Playgroud)

我希望这是有道理的 - 有没有人有任何想法?谢谢你的任何建议!干杯戴夫

python pyqt

5
推荐指数
1
解决办法
7383
查看次数

PyQt更新gui

我正在尝试通过QThreadPyQt 更新Qt GUI对象中的文本,但我只是得到错误QPixmap: It is not safe to use pixmaps outside the GUI thread,然后它崩溃了.我真的很感激任何帮助,谢谢.

class MainWindow(QMainWindow, Ui_MainWindow):

    def __init__(self, parent = None):
        QMainWindow.__init__(self, parent)
        self.setupUi(self)
        self.output = Output()

    def __del__ (self):
        self.ui = None

    @pyqtSignature("")
    def on_goBtn_released(self):
        threadnum = 1
        #start threads
        for x in xrange(threadnum):
            thread = TheThread() 
            thread.start()


class Output(QWidget, Ui_Output):

    def __init__(self, parent = None):
        QWidget.__init__(self, parent)
        self.setupUi(self)
        self.ui = Ui_Output
        self.show()

    def main(self):
        self.textBrowser.append("sdgsdgsgsg dsgdsg dsgds gsdf")



class TheThread(QtCore.QThread):

    trigger = pyqtSignal() …
Run Code Online (Sandbox Code Playgroud)

python pyqt

4
推荐指数
1
解决办法
1万
查看次数

以LCD格式显示系统时钟时间

我只想以LCD格式显示系统时钟时间.我也希望用hh:mm:ss格式显示时间.我的代码如下.但是当我运行它时,它并不像我预期的那样.有谁能解释为什么?

import sys
from PySide import QtGui, QtCore

class Example(QtGui.QWidget):

    def __init__(self):
        super(Example, self).__init__()
        self.initUI()
        timer = QtCore.QTimer(self)
        timer.timeout.connect(self.showlcd)
        timer.start(1000)
        self.showlcd()

    def initUI(self):

        self.lcd = QtGui.QLCDNumber(self)
        self.setGeometry(30, 30, 800, 600)
        self.setWindowTitle('Time')

        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(self.lcd)
        self.setLayout(vbox)

        self.show()

    def showlcd(self):
        time = QtCore.QTime.currentTime()
        text = time.toString('hh:mm:ss')
        self.lcd.display(text)


def main():

    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()
Run Code Online (Sandbox Code Playgroud)

python pyqt4

2
推荐指数
1
解决办法
4719
查看次数

如何连接QLineEdit focusOutEvent

QLineEdit在Designer的帮助下设计了一个带有PyQt4 的窗口.我转换.ui.py使用pyuic4.我创建了另一个.py文件并导入和子类化Ui_Class.

我想在QLineEdit失去焦点时执行一些任务.

只需按行按钮点击事件i即可连接QLineEdit丢失焦点事件

python pyqt4 qlineedit

2
推荐指数
1
解决办法
4189
查看次数

未解决的导入:webbrowser

当我在Aptana Studio 3中运行以下代码时,在运行OS X 10.6(Snowleopard)的iMac上构建:3.0.9.201202141038,出现以下错误。

import webbrowser
webbrowser.open('http://google.com')


Traceback (most recent call last):   File
"/Users/gianl/Documents/Aptana Studio 3 Workspace/Thought Log 3 w
dropbox/src/webbrowser.py", line 1, in <module>
    import webbrowser   File "/Users/gianl/Documents/Aptana Studio 3 Workspace/Thought Log 3 w dropbox/src/webbrowser.py", line 3, in
<module>
    webbrowser.open('http://google.com') AttributeError: 'module' object has no attribute 'open'
Run Code Online (Sandbox Code Playgroud)

当我在终端中没有收到此错误时,为什么会在Aptana中收到此错误?

python aptana python-webbrowser

1
推荐指数
1
解决办法
3678
查看次数

开发pyqt4树小部件

我需要在pyqt中写一个树?它看起来像这样:

Clients(this is text)  
   Type A (this is a Clients child and has a checkbox)  
    Type B (this is a Clients child and has a checkbox)  
Vendors(this is text) 
    Mary  (this is a Vendors child and has a checkbox)   
    Arnold  (this is a Vendors child and has a checkbox)  
Time Period  
    Init(this is a Time Period child, and would be a calendarWidget for date selection)  
    End (this is a Time Period child, and would be a calendarWidget for date selection) …
Run Code Online (Sandbox Code Playgroud)

qtreewidget pyqt4 qtreeview

1
推荐指数
1
解决办法
1万
查看次数

使用matplotlib如何在python中使用给定数据绘制直方图

这是数据:

111, 3  
122, 4  
155, 3  
192, 5  
11,  9  
123, 10  
120, 23
Run Code Online (Sandbox Code Playgroud)

现在我怎么能用这两组数据绘制直方图matplotlib.请帮忙.

python plot matplotlib histogram

0
推荐指数
1
解决办法
8518
查看次数