import psutil as p
bg_app_dict = {}
count = 0
for process in p.process_iter():
count += 1
if count <= 6:
name = process.name()
cpu_usage = p.cpu_percent()
print("Name : ", name, "CPU Usage : ", cpu_usage)
bg_app_dict.update({name : cpu_usage})
keymax = max(bg_app_dict, key = bg_app_dict.get)
print(keymax)
keymin = min(bg_app_dict, key = bg_app_dict.get)
bg_app_list = [keymax, keymin]
print(bg_app_list)
bg_app = bg_app_dict.values()
max_bg_app = max(bg_app)
print(max_bg_app)
min_bg_app = min(bg_app)
print(min_bg_app)
max_min_bg_app_list = [max_bg_app, min_bg_app]
print(max_min_bg_app_list)
plt.figure(figsize = (15, 7))
plt.xlabel("Applications")
plt.ylabel("CPU Usage")
plt.bar(bg_app_list, max_min_bg_app_list, width = 0.5, color = ("Red", "Blue"))
plt.show()
#๐ Error for colour values in matplotlib
44 messages ยท Page 1 of 1 (latest)
Hey @winged solar!
It looks like you pasted Python code without syntax highlighting.
Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.
To do this, use the following method:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
You can **edit your original message** to correct your code block.
@winged solar
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
Traceback:
Name : System Idle Process CPU Usage : 30.3
System Idle Process
['System Idle Process', 'System Idle Process']
30.3
30.3
[30.3, 30.3]
Name : System CPU Usage : 0.0
System Idle Process
['System Idle Process', 'System']
30.3
0.0
[30.3, 0.0]
Name : Registry CPU Usage : 25.0
System Idle Process
['System Idle Process', 'System']
30.3
0.0
[30.3, 0.0]
Name : smss.exe CPU Usage : 0.0
System Idle Process
['System Idle Process', 'System']
30.3
0.0
[30.3, 0.0]
Name : svchost.exe CPU Usage : 0.0
System Idle Process
['System Idle Process', 'System']
30.3
0.0
[30.3, 0.0]
Name : csrss.exe CPU Usage : 50.0
csrss.exe
['csrss.exe', 'System']
50.0
0.0
[50.0, 0.0]
Traceback (most recent call last):
File ~\anaconda3\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File c:\users\admin\desktop\pprojects(adv)\untitled0.py:48
plt.bar(bg_app_list, max_min_bg_app_list, width = 0.5, color = ("Red", "Blue"))
File ~\anaconda3\Lib\site-packages\matplotlib\pyplot.py:2742 in bar
return gca().bar(
File ~\anaconda3\Lib\site-packages\matplotlib_init_.py:1465 in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File ~\anaconda3\Lib\site-packages\matplotlib\axes_axes.py:2481 in bar
color = itertools.chain(itertools.cycle(mcolors.to_rgba_array(color)),
File ~\anaconda3\Lib\site-packages\matplotlib\colors.py:489 in to_rgba_array
raise ValueError(f"{c!r} is not a valid color value.")
ValueError: 'Red' is not a valid color value.
don't capitalise https://matplotlib.org/stable/gallery/color/named_colors.html
sorry what?
The line plt.bar(bg_app_list, max_min_bg_app_list, width = 0.5, color = ("Red", "Blue")) keeps giving an error
idk why
and wdym capitalise?
I gave you a link to the list of all named colours in matplotlib. You need to use their names exactly as written on that page. For example, 'Red' will give an error, but 'red' or 'r' is a valid colour
Still no :(
Name : System Idle Process CPU Usage : 61.5
System Idle Process
['System Idle Process', 'System Idle Process']
61.5
61.5
[61.5, 61.5]
Name : System CPU Usage : 100.0
System
['System', 'System Idle Process']
100.0
61.5
[100.0, 61.5]
Name : Registry CPU Usage : 0.0
System
['System', 'Registry']
100.0
0.0
[100.0, 0.0]
Name : smss.exe CPU Usage : 100.0
System
['System', 'Registry']
100.0
0.0
[100.0, 0.0]
Name : svchost.exe CPU Usage : 50.0
System
['System', 'Registry']
100.0
0.0
[100.0, 0.0]
Name : csrss.exe CPU Usage : 0.0
System
['System', 'Registry']
100.0
0.0
[100.0, 0.0]
Traceback (most recent call last):
File ~\anaconda3\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File c:\users\admin\desktop\pprojects(adv)\untitled0.py:48
plt.bar(bg_app_list, max_min_bg_app_list, width = 0.5, color = ("red", "blue"))
File ~\anaconda3\Lib\site-packages\matplotlib\pyplot.py:2742 in bar
return gca().bar(
File ~\anaconda3\Lib\site-packages\matplotlib_init_.py:1465 in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File ~\anaconda3\Lib\site-packages\matplotlib\axes_axes.py:2481 in bar
color = itertools.chain(itertools.cycle(mcolors.to_rgba_array(color)),
File ~\anaconda3\Lib\site-packages\matplotlib\colors.py:489 in to_rgba_array
raise ValueError(f"{c!r} is not a valid color value.")
ValueError: 'red' is not a valid color value.
ValueError: 'r' is not a valid color value.
I just ran your code and it works fine even with 'Red', hm... what version of matplotlib are you using?
if I remember correctly, matplotlib is one of spyder's dependencies so it should get installed automatically
print(matplotlib.__version__)
no but that shouldn't be an issue, I'm a bit confused why it doesn't work on your machine
if you use 'red' do you still get an error?
oh you do, I just read the traceback in full
yeah i'm not sure why
should i try deleting and redownloading spyder?
or maybe some other troubleshooting methods?
anyone suggest anything?
have you tried using a float in the second position (replacing blue)? Something like
plt.bar(bg_app_list, max_min_bg_app_list, width = 0.5, color = ("Red", 0.5))
the number is for the alpha channel. It wont' solve your problem, but I'm wondering if that works ๐คท
This is the logic for a tuple when the len is 2 in matplotlib: https://github.com/matplotlib/matplotlib/blob/5e347777192b37ac77decc4f975e53ed9d87973b/lib/matplotlib/colors.py#L321-L325
lib/matplotlib/colors.py lines 321 to 325
if isinstance(c, tuple) and len(c) == 2:
if alpha is None:
c, alpha = c
else:
c = c[0]```
The other thing you can maybe try is using the hex values of the colors instead:
# This uses the the red and blue hex values
plt.bar(bg_app_list, max_min_bg_app_list, width = 0.5, color = ("#ff0000", "#0000ff"))
from bs4 import BeautifulSoup
import time
# Function to log in to Roblox
def login(username, password):
login_url = "https://www.roblox.com/newlogin"
session = requests.Session()
login_data = {
"username": username,
"password": password
}
session.post(login_url, data=login_data)
return session
# Function to get free limited items
def get_free_limited_items(session):
items_url = "https://www.roblox.com/catalog/?Category=13&Subcategory=16"
response = session.get(items_url)
soup = BeautifulSoup(response.text, "html.parser")
item_containers = soup.find_all("li", class_="item-card")
free_limited_items = []
for item in item_containers:
item_name = item.find("a", class_="item-card-name").text.strip()
item_link = item.find("a", class_="item-card-link")["href"]
if "Limited" in item.find("div", class_="item-card-status").text:
free_limited_items.append({"name": item_name, "link": item_link})
return free_limited_items
# Function to claim free items
def claim_items(session, items):
for item in items:
response = session.get(item["link"])
# Implement logic to claim item (e.g., clicking buttons, submitting forms)
print(f"Claimed item: {item['name']}")
time.sleep(1) # Add a delay to avoid spamming requests
def check_and_claim(username, password):
session = login(username, password)
while True:
free_limited_items = get_free_limited_items(session)
claim_items(session, free_limited_items)
time.sleep(10)
if should_stop(): # Check if the script should stop
break
# Function to determine whether the script should stop
def should_stop():
return False
# Example usage
if __name__ == "__main__":
username = "username"
password = "password"
check_and_claim(username, password)
why my code arent working
Hi @past roost you probably meant to start your own help thread. This thread is for @winged solar
cant creat
i cant post
@past roost maybe try asking for help posting in #python-community or #community-meta ?
ok thx
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.