pyqt5 how to make a checkbox lock two Qsliders together [closed] - pyqt5

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have made a GUI using using Qt Designer running in python here
How do I add code to my project to add a checkbox that locks (have their values changed together whatever they may be. 0 - 100 range) both my Qsliders together. See picture below.
Please feel free to ask if more info is needed.

You would connect each slider's valueChanged signal to the other's setValue slot when the checkbox is checked, and disconnect when unchecked.
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class Template(QWidget):
def __init__(self):
super().__init__()
vbox = QVBoxLayout(self)
vbox.addWidget(QSlider(Qt.Horizontal))
vbox.addWidget(QCheckBox('Lock', toggled=self.toggleLocked))
vbox.addWidget(QSlider(Qt.Horizontal))
def toggleLocked(self, state):
s1, s2 = self.findChildren(QSlider)
if state:
s2.setValue(s1.value())
s1.valueChanged[int].connect(s2.setValue)
s2.valueChanged[int].connect(s1.setValue)
else:
s1.valueChanged[int].disconnect()
s2.valueChanged[int].disconnect()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Template()
window.show()
sys.exit(app.exec_())

Related

How to apply machine learning to a csv file to predict future values [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last month.
Improve this question
I'm curious about ML and I wonder if some of you guys could help me getting started.
I have a dataset in a csv format like this:
Date
First
Second
Third
2022-12-30
5402
8694
8648
2022-12-29
3804
8529
6690
2022-12-28
3192
2779
2166
I want to predict first, second, and third values in the future time e.g. 2022-12-31.
What kind of algorithm is suitable to do this job? How do I have to implement this in my Jupyter notebook? Any example and/or reference of this problem will be so helpful to me. This is for predicting a 4-digit lottery game.
I have let panda to read my csv file and set it to a variable named "dataset"
import pandas as pd
import numpy as np
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
dataset=pd.read_csv("C:/Users/Administrator/Desktop/data.csv")
dataset['Date'] = pd.to_datetime(dataset.Date)
Here you are predicting the trend of the random winning number so linear regression would be the ideal choice for this.

Is there a python tensorflow/pytorch function like the x.toPixels tensorflowjs function? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I need a replacement for the tf.browser.toPixels() tensorflowJS function. Trying to port some code to python and I'm wondering if there is a quick way around this.
In the browser this gets really simple and we just callback new frames and draw into a canvas. But in python development, say in matplotlib or tkinter, I guess I'm gonna need some tricks.
Is there a (not super big) solution for this?
Thanks
Let say you are having a 2D tensor img which run it in your browser like tf.browser.toPixels(img). You can draw similar images using OpenCV and matplotlib like:
Using Pytorch
import matplotlib.pyplot as plt
# If your data is in GPU:
img_np = img.cpu().numpy()
# Using OpenCV
cv2.imwrite(img_np.astype(np.uint8), "image.png")
# Using matplotlib
plt.imshow(img_np)
Tensorflow
```python
import matplotlib.pyplot as plt
img_np = img.numpy()
# Using OpenCV
cv2.imwrite(img_np.astype(np.uint8), "image.png")
# Using matplotlib
plt.imshow(img_np)
Also, if you have a 3D tensor ( i.e. n x m x 3) you can still average the bands and make a 2D tensor out of it and plot them the same way.

catplot issue Axes object [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Supposing I have a Pandas DataFrame variable called df which has columns col1, col2, col3, col4.
Using sns.catplot() everything works fine:
fig = sns.catplot(x='col1', y='col2', kind='bar', data=df, col='col3', hue='col4')
However, as soon as I write:
fig.axes[0].get_xlabel()
I get the following error:
AttributeError: 'numpy.ndarray' object has no attribute 'get_xlabel'
I know I can use sns.barplot() with ax parameter but my goal is to keep using sns.catplot() and get an Axes object from fig.axes[0].
If you check the help page, it writes:
Figure-level interface for drawing categorical plots onto a FacetGrid
So to get the xlabel like you did:
import seaborn as sns
df = sns.load_dataset("tips")
g = sns.catplot(x='day', y='tip', kind='bar', data=df, col='smoker', hue='sex')
In this example, you have a facet plot that is 1 by 2, so the axes for the plots are stored in an (1,2) array:
g.axes.shape
(1, 2)
And to access for example the one of the left (Smoker ="Yes"), you do:
g.axes[0,0].get_xlabel()
'day'
To change the label:
g.axes[0,0].set_xlabel('day 1')
g.fig

How do I replicate this graph? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
X axis contains 80 different variables. The green dots represent performance. The red/blue lines denote the increase/decrease in performance respectively. I was thinking of a box plot/scatter plot, but what I need I think is a combination of the two. Any help is appreciated.
I would make a scatter plot where the dot represents performance and the red/blue lines are represented as yerr.
import numpy as np
import matplotlib.pyplot as plt
y = [20, 30, 40]
x = np.arange(0,len(y), 1)
xlabel = ['airplane', 'apple', 'banana']
change = [-10,0,+3]
y_err,err_color = [],[]
for i in change:
if i < 0 :
y_err.append([[abs(i)],[0]])
err_color.append(['blue'])
else:
y_err.append([[0],[i]])
err_color.append(['red'])
for i in range(len(x)):
print(y_err[i])
plt.errorbar(x[i], y[i], yerr = y_err[i], color = 'green',fmt='.',ecolor =
err_color[i])
plt.xticks(x, xlabel,rotation = 'vertical')
plt.show()

Basic Image Classification using tensorflow [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
train = 'C:\ProgramData\Anaconda3\animal train'
test = 'C:\ProgramData\Anaconda3\animal test'
lr = 0.001
def label_image(img):
word_label = img.split('.')[-3]
if word_label == "cat": return [1,0]
elif word_label == "dog": return [0,1]
def create_train_data():
training_data = []
for img in tqdm(os.listdir(train)):
label = label_img(img)
path = os.path.join(train,img)
img = cv2.resize(cv2.imread(path,cv2.IMREAD_GRAYSCALE),(50,50))
training_data.append([np.array(img), np.array(label)])
shuffle(training_data)
return(training_data)
I am new to tensorflow and this is my first project ( Cat vs Dog Image Classification)
Can you please explain each line in detail what is create_train_data() function actually doing?
Image reading in OpenCV goes as follows
img = cv2.imread("path/to/image", flags)
Now "path/to/image" is either your working directory or absolute path.
path = os.path.join(train,img) in your code is creating absolute path. I think since you are in working directory, just directly reading image also should work in this case.