Skip to content

Commit

Permalink
按钮功能改为清除绘图区域;增加了电流-转速曲线
Browse files Browse the repository at this point in the history
  • Loading branch information
Athameral committed Dec 2, 2023
1 parent a0e092c commit 72e103a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/__pycache__
/.idea
/build/
/dist/
/MnD.spec
12 changes: 6 additions & 6 deletions Main_Window.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ def setupUi(self, MainUI):

self.horizontalLayout_6.addWidget(self.Figure_SelectBox)

self.Button_Draw = QPushButton(MainUI)
self.Button_Draw.setObjectName(u"Button_Draw")
self.Button_Clear = QPushButton(MainUI)
self.Button_Clear.setObjectName(u"Button_Clear")
sizePolicy8 = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
sizePolicy8.setHorizontalStretch(2)
sizePolicy8.setVerticalStretch(0)
sizePolicy8.setHeightForWidth(self.Button_Draw.sizePolicy().hasHeightForWidth())
self.Button_Draw.setSizePolicy(sizePolicy8)
sizePolicy8.setHeightForWidth(self.Button_Clear.sizePolicy().hasHeightForWidth())
self.Button_Clear.setSizePolicy(sizePolicy8)

self.horizontalLayout_6.addWidget(self.Button_Draw)
self.horizontalLayout_6.addWidget(self.Button_Clear)


self.verticalLayout_4.addLayout(self.horizontalLayout_6)
Expand Down Expand Up @@ -305,6 +305,6 @@ def retranslateUi(self, MainUI):
self.Label_U.setText(QCoreApplication.translate("MainUI", u"\u8f93\u5165\u7535\u538b", None))
self.label_U_unit.setText(QCoreApplication.translate("MainUI", u"V", None))
self.Figure_Name.setText(QCoreApplication.translate("MainUI", u"\u673a\u7535\u53c2\u6570\u66f2\u7ebf", None))
self.Button_Draw.setText(QCoreApplication.translate("MainUI", u"\u7ed8\u5236", None))
self.Button_Clear.setText(QCoreApplication.translate("MainUI", u"\u6e05\u9664", None))
# retranslateUi

34 changes: 22 additions & 12 deletions MnD.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from threading import Thread, Lock
from threading import Thread

import numpy as np
from PySide6.QtWidgets import QApplication, QWidget
Expand Down Expand Up @@ -68,7 +68,7 @@ def change_param_texts():

# 选择绘制类型

figure_type = ("功率", "电动势", "电流", "转速", "转矩", "效率")
figure_type = ("功率", "电动势", "电流", "转速", "转矩", "效率", "电流-转速")
ui.Figure_SelectBox.addItems(figure_type)

# 定义绘制函数
Expand All @@ -78,8 +78,9 @@ def change_param_texts():
canvas_n = MplCanvas()
canvas_T = MplCanvas()
canvas_eta = MplCanvas()
canvas_I_vs_n = MplCanvas()

canvas_list = (canvas_Power, canvas_E, canvas_I, canvas_n, canvas_T, canvas_eta)
canvas_list = (canvas_Power, canvas_E, canvas_I, canvas_n, canvas_T, canvas_eta, canvas_I_vs_n)

for canvas in canvas_list:
canvas.ax.grid()
Expand All @@ -90,14 +91,15 @@ def change_param_texts():
canvas_n.ax.set_title("n")
canvas_T.ax.set_title("T")
canvas_eta.ax.set_title("eta")

figure_drawing = False

canvas_I_vs_n.ax.set_title("I-n")

# 一般来说,绘制很快,200ms左右就可以绘制完成
# 当触发频率不太高时,不用自旋锁也没有什么问题
# 但是在某些场景下,比如拖动滑动条时,触发会非常密集
# 浪费资源且不说,这时一张图上会出现多条曲线,非常恐怖,兄弟。XD
figure_drawing = False


def draw_figure():
global figure_drawing
if figure_drawing:
Expand All @@ -117,11 +119,12 @@ def draw_figure():
canvas_Power.ax.plot(R_L, result[2], label="P2", color="#9199ff")
canvas_Power.ax.legend()

canvas_E.ax.plot(R_L, result[3],color="#136f37")
canvas_I.ax.plot(R_L, result[4],color="#008068")
canvas_n.ax.plot(R_L, result[5],color="#008e9f")
canvas_T.ax.plot(R_L, result[6],color="#0098d1")
canvas_eta.ax.plot(R_L, result[7],color="#009cf4")
canvas_E.ax.plot(R_L, result[3], color="#136f37")
canvas_I.ax.plot(R_L, result[4], color="#008068")
canvas_n.ax.plot(R_L, result[5], color="#008e9f")
canvas_T.ax.plot(R_L, result[6], color="#0098d1")
canvas_eta.ax.plot(R_L, result[7], color="#009cf4")
canvas_I_vs_n.ax.plot(result[5], result[4], color="#008068")

# TO DO:
# 保存Line2D对象,避免重复新建对象,以改进颜色变化问题
Expand Down Expand Up @@ -152,8 +155,15 @@ def switch_figure():
pass


def clear_figures():
for canvas in canvas_list:
canvas.ax.clear()
canvas.ax.grid()
canvas.draw()


# 绑定绘制按钮和ComboBox
ui.Button_Draw.clicked.connect(draw_8figures)
ui.Button_Clear.clicked.connect(clear_figures)
ui.Figure_SelectBox.currentIndexChanged.connect(switch_figure)

switch_figure()
Expand Down
4 changes: 2 additions & 2 deletions MnD.ui
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,15 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="Button_Draw">
<widget class="QPushButton" name="Button_Clear">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>绘制</string>
<string>清除</string>
</property>
</widget>
</item>
Expand Down
7 changes: 0 additions & 7 deletions motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,3 @@ def calc_args(
print(calc_args(0.2, 600, 220, 5))
import numpy as np
import matplotlib.pyplot as plt

# calc2 = np.vectorize(calc_args, excluded=[0, 1, 2])
# rl = np.linspace(100, 1, 1000)
# arr = calc2(0.2, 200, 220, rl)
# arr1 = np.asmatrix(arr)
# plt.plot(rl, arr[5])
# plt.show()

0 comments on commit 72e103a

Please sign in to comment.