#๐Ÿ”’ Error using matplotlib

23 messages ยท Page 1 of 1 (latest)

fading zenith
#

Code:

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 = ("Pink", "Blue"))
lilac gorgeBOT
#

Hey @fading zenith!

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.
lilac gorgeBOT
#

@fading zenith

Python help channel opened

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.

fading zenith
#

Traceback when run is:

#

runfile('C:/Users/Admin/Desktop/PProjects(ADV)/untitled0.py', wdir='C:/Users/Admin/Desktop/PProjects(ADV)')
Name : System Idle Process CPU Usage : 70.2
System Idle Process
['System Idle Process', 'System Idle Process']
70.2
70.2
[70.2, 70.2]
Name : System CPU Usage : 0.0
System Idle Process
['System Idle Process', 'System']
70.2
0.0
[70.2, 0.0]
Name : Registry CPU Usage : 100.0
Registry
['Registry', 'System']
100.0
0.0
[100.0, 0.0]
Name : smss.exe CPU Usage : 100.0
Registry
['Registry', 'System']
100.0
0.0
[100.0, 0.0]
Name : chrome.exe CPU Usage : 0.0
Registry
['Registry', 'System']
100.0
0.0
[100.0, 0.0]
Name : svchost.exe CPU Usage : 0.0
Registry
['Registry', 'System']
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 = ("Pink", "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: 'Pink' is not a valid color value.

#

kindly help

remote blade
#

im just gonna edge you till you get it

fading zenith
#

no colour works

#

idk why

#

And ayo?

#

please help anyone?

tropic viper
#

does the bar function support colors as a tuple? or is it looking for a list? Also, just for simplicity, what happens if you try red instead

fading zenith
#

nope red too doesn't work. It keeps asking for a color value and its not accepting rgb values either

#

list doesn't work and the tuple is'nt working either

#

i'm using spyder to code with anaconda prompt

#

so matplotlib is already installed

#

thanks for the help tho...

viscid vortex
#

Your code works for me

#

No error

#

I am not using spyder

lilac gorgeBOT
#
Python help channel closed

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.