To solve this optimization problem, we need to define the decision variables, the objective function, and the constraints.

Let's denote:
- $x$ as the amount invested in the action movie,
- $y$ as the amount invested in the animation movie.

The objective is to maximize earnings. Given that the return on investment for the action movie is 9% and for the animation movie is 6%, the total earnings can be represented as $0.09x + 0.06y$.

There are several constraints:
1. The total amount invested cannot exceed $500,000: $x + y \leq 500,000$.
2. The amount invested in the animation movie must be at least three times the amount invested in the action movie: $y \geq 3x$.
3. The amount invested in the animation movie cannot exceed $400,000: $y \leq 400,000$.

We also know that $x \geq 0$ and $y \geq 0$, as negative investments do not make sense in this context.

To find the optimal investment amounts using Gurobi in Python, we can use the following code:

```python
from gurobipy import *

# Create a new model
m = Model("Movie_Investment")

# Define variables
x = m.addVar(name="Action_Movie", vtype=GRB.CONTINUOUS, lb=0)
y = m.addVar(name="Animation_Movie", vtype=GRB.CONTINUOUS, lb=0)

# Set the objective function: Maximize earnings
m.setObjective(0.09*x + 0.06*y, GRB.MAXIMIZE)

# Add constraints
m.addConstr(x + y <= 500000, name="Total_Investment")
m.addConstr(y >= 3*x, name="Animation_vs_Action")
m.addConstr(y <= 400000, name="Max_Animation")

# Optimize model
m.optimize()

# Print results
if m.status == GRB.OPTIMAL:
    print("Optimal solution found:")
    print(f"Action Movie Investment: ${x.x:.2f}")
    print(f"Animation Movie Investment: ${y.x:.2f}")
    print(f"Total Earnings: ${0.09*x.x + 0.06*y.x:.2f}")
else:
    print("No optimal solution found")
```