私信  •  关注

ImportanceOfBeingErnest

ImportanceOfBeingErnest 最近创建的主题
ImportanceOfBeingErnest 最近回复了
8 年前
回复了 ImportanceOfBeingErnest 创建的主题 » 如何使用pyqt5 python[duplicate]在测验应用程序中显示计时器

你不能使用 time.sleep 在pyqt主事件循环中,因为它会停止GUI事件循环的响应。

pyqt中的解决方案可能是这样的,使用 QTimer

import sys
from PyQt4 import QtGui, QtCore

application = QtGui.QApplication(sys.argv)

i=0
timer = QtCore.QTimer()

def num():
    global i, timer
    if i <999:
        print ( i )
        i += 1
    else:
        timer.stop()

timer.timeout.connect(num)
timer.start(2000)

sys.exit(application.exec_())
6 年前
回复了 ImportanceOfBeingErnest 创建的主题 » 使用Python2.7.15时matplotlib绘图不正确,但使用2.7.10时不正确

从matplotlib文档 bar

Version 1.3.1

align :[边缘|中心],可选, 默认:边

Version 2.2.3

排列 :{'center','edge'},可选, 默认:“居中”

使用 align="edge" 以获取两个版本中的第一个图像。使用 align="center" 以获取两个版本中的第二个图像。

6 年前
回复了 ImportanceOfBeingErnest 创建的主题 » 在二维平面上用python绘制y=f(x)的图形

因为这个问题是用matplotlib标记的,所以这里是如何完成的;例如,在区间[-3,3]中,plot y=f(x)=x^2。

import numpy as np
import matplotlib.pyplot as plt

interval = -3,3
f = lambda x: x**2

x = np.linspace(*interval, 301)
plt.plot(x, f(x))

plt.show()

enter image description here

7 年前
回复了 ImportanceOfBeingErnest 创建的主题 » 如何在python中使用seaborn relplot创建的子块中关闭y轴标题、图例?[复制品]

您可以访问facetgrid的轴( g = sns.FacetGrid(...) 通过 g.axes . 这样,您就可以自由使用任何想要调整绘图的matplotlib方法。

更改标题 :

axes = g.axes.flatten()
axes[0].set_title("Internal")
axes[1].set_title("External")

更改标签 :

axes = g.axes.flatten()
axes[0].set_ylabel("Number of Defects")
for ax in axes:
    ax.set_xlabel("Percentage Depth")

注意,我更喜欢上面那些 FacetGrid 内部 g.set_axis_labels set_titles 方法,因为它使标记哪些轴更加明显。

7 年前
回复了 ImportanceOfBeingErnest 创建的主题 » 将python plot存储为变量并重新加载它以覆盖另一个plot

我将把这个问题解释为关于matplotlib的问题(因为matplotlib被标记了),但是当然还有其他python绘图工具,它们的行为可能不同。

在matplotlib中,一个艺术家(例如一条线)必然是一个图形的一部分。不能将同一艺术家添加到多个图形中。
所以通常的解决办法是不想复制艺术家本身,而是复制艺术家的创作过程。

def mycos(x, ax=None, **kwargs):
    ax = ax or plt.gca()
    ax.plot(x, np.cos(x), **kwargs)

def mysin(x, ax=None, **kwargs):
    ax = ax or plt.gca()
    ax.plot(x, np.sin(x), **kwargs)

x = np.linspace(0,2*np.pi)

# Create one figure with two subplots, plot one function in each subplot
fig, axes = plt.subplots(2)
mycos(x, ax=axes[0])
mysin(x, ax=axes[1])

# Create another figure with one subplot, plot both functions
fig, ax = plt.subplots(1)
mycos(x, ax=ax)
mysin(x, ax=ax)