import discretize
import matplotlib.pyplot as plt


def run(plotIt=True):
    M = discretize.TreeMesh([8, 8])

    def refine(cell):
        xyz = cell.center
        dist = ((xyz - [0.25, 0.25]) ** 2).sum() ** 0.5
        if dist < 0.25:
            return 3
        return 2

    M.refine(refine)
    if plotIt:
        M.plotGrid(nodes=True, centers=True, faces_x=True)
        plt.legend(
            (
                "Grid",
                "Cell Centers",
                "Nodes",
                "Hanging Nodes",
                "X faces",
                "Hanging X faces",
            )
        )


if __name__ == "__main__":
    run()
    plt.show()

import discretize
import matplotlib.pyplot as plt


def run(plotIt=True):
    M = discretize.TreeMesh([8, 8])

    def refine(cell):
        xyz = cell.center
        dist = ((xyz - [0.25, 0.25]) ** 2).sum() ** 0.5
        if dist < 0.25:
            return 3
        return 2

    M.refine(refine)
    if plotIt:
        M.plotGrid(nodes=True, centers=True, faces_x=True)
        plt.legend(
            (
                "Nodes",
                "Hanging Nodes",
                "Cell Centers",
                "X faces",
                "Hanging X faces",
                "Grid",
            )
        )


if __name__ == "__main__":
    run()
    plt.show()

Switch order (again) of legend for example
Switch order (again) of legend for example

  import discretize
  import matplotlib.pyplot as plt
  
  
  def run(plotIt=True):
      M = discretize.TreeMesh([8, 8])
  
      def refine(cell):
          xyz = cell.center
          dist = ((xyz - [0.25, 0.25]) ** 2).sum() ** 0.5
          if dist < 0.25:
              return 3
          return 2
  
      M.refine(refine)
      if plotIt:
          M.plotGrid(nodes=True, centers=True, faces_x=True)
          plt.legend(
              (
-                 "Grid",
-                 "Cell Centers",
                  "Nodes",
                  "Hanging Nodes",
+                 "Cell Centers",
                  "X faces",
                  "Hanging X faces",
+                 "Grid",
              )
          )
  
  
  if __name__ == "__main__":
      run()
      plt.show()
  
Switch order (again) of legend for example
## Code Before:
import discretize
import matplotlib.pyplot as plt


def run(plotIt=True):
    M = discretize.TreeMesh([8, 8])

    def refine(cell):
        xyz = cell.center
        dist = ((xyz - [0.25, 0.25]) ** 2).sum() ** 0.5
        if dist < 0.25:
            return 3
        return 2

    M.refine(refine)
    if plotIt:
        M.plotGrid(nodes=True, centers=True, faces_x=True)
        plt.legend(
            (
                "Grid",
                "Cell Centers",
                "Nodes",
                "Hanging Nodes",
                "X faces",
                "Hanging X faces",
            )
        )


if __name__ == "__main__":
    run()
    plt.show()

## Instruction:
Switch order (again) of legend for example
## Code After:
import discretize
import matplotlib.pyplot as plt


def run(plotIt=True):
    M = discretize.TreeMesh([8, 8])

    def refine(cell):
        xyz = cell.center
        dist = ((xyz - [0.25, 0.25]) ** 2).sum() ** 0.5
        if dist < 0.25:
            return 3
        return 2

    M.refine(refine)
    if plotIt:
        M.plotGrid(nodes=True, centers=True, faces_x=True)
        plt.legend(
            (
                "Nodes",
                "Hanging Nodes",
                "Cell Centers",
                "X faces",
                "Hanging X faces",
                "Grid",
            )
        )


if __name__ == "__main__":
    run()
    plt.show()
