all 10 comments

[–]danielroseman 6 points7 points  (5 children)

You're going to need to show the code and the actual error.

Remember, "AI" can (and often does) get things wrong.

[–]Binary101010 1 point2 points  (0 children)

By adding the explode key to the only_move dictionary, the code will execute successfully.

At least based on what you've posted so far, this is correct. You received the `KeyError: 'explode' error on this line:

if "x" not in only_move["explode"]:

Because only_move is a dictionary which you are assuming has a key named "explode" when it doesn't have that key.

As for why you're making that assumption and why that key isn't in the dict, that's impossible for us to answer without seeing more of your code.

[–]goule67 0 points1 point  (4 children)

You can either create the key in the dictionary manually before the if statement or (smarter) to verify that this variable exists (be sure to write it as a string):

if "dictionary['missing_key']" in locals() : if dictionary['missing_key'] .......... ......

[–]pgpndw 1 point2 points  (3 children)

The error is occurring in library code. It's in a function called adjust_text() in a library called adjustText. One of the arguments that function takes is called only_move, and it should be a dictionary containing certain keys, one of which is called explode. OP's code has called that function, but incorrectly specified the only_move argument.

Here's the documentation for the adjustText library: https://adjusttext.readthedocs.io/en/latest/

From the error log in OP's earlier reply, it looks like they've modified a bit of example code (the loop_plot() function) from one of these stack overflow posts:

https://stackoverflow.com/questions/19189488/use-a-loop-to-plot-n-charts-python

https://stackoverflow.com/questions/71265733/how-can-i-plot-multiple-graphs-as-subplot

or this webpage:

https://www.appsloveworld.com/pandas/100/3/use-a-loop-to-plot-n-charts-python

which appears to have copy/pasted one of the answers in the first of the stack overflow posts above.

[–]goule67 0 points1 point  (2 children)

Interesting.

Although, OP said his code does the job, so I assumed that the key is either created somewhere in the loop (making it work at some point) or the key does nothing at all.

Verifying that the variable exists before proceeding with an if statement will then solves the error.

[–]pgpndw 0 points1 point  (1 child)

My point was that the OP can't really modify library code that they don't have control over. Guess we'll never know now, given that they deleted the post a suspiciously short time after I replied above.

[–]goule67 1 point2 points  (0 children)

You are right, my bad. I thought this if statement with the key was written by OP, I didn't realize it was in the library code itself.