As you can see in the screenshot, I have a layer with a lot of empty categories (0 features). Is it a way to automatically remove this categories from TOC? To do it manually, it is complicated cause I have a lot of empty categories.
I don't want to reclassified, cause I don't want to lose my symbology!
EDIT
@Mayo:
Are you sure it works in this case? See second capture.
In case, value is the same as legend, it works… but in the capture, you'll see it is different. And after using the python code, the category is empty.
Best Answer
Paste this script in the python console, select the layer where you want to remove the nonexistent categories and click run.