Verified Commit 8f9b180c authored by Yunus Sevinchan's avatar Yunus Sevinchan
Browse files

Fix bug in SimpleFlocking plot; use centralised cmap definition

parent 83ce73bc
Loading
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -95,22 +95,13 @@ def agents_in_domain(
    hlpr.ax.set_ylim(0, space_extent[1])
    hlpr.ax.set_aspect("equal")

    # Draw initial frame and colorbar
    collection = draw_agents(ds.isel(time=0), hlpr=hlpr, **plot_kwargs)

    if add_colorbar:
        cm.create_cbar(
            collection,
            fig=hlpr.fig,
            ax=hlpr.ax,
            **(cbar_kwargs if cbar_kwargs else {}),
        )
    # TODO Adapt for case where *no* animation is desired

    # .. Animation ............................................................

    def update_position_and_orientation():
        collection = None
        for _t, _ds in ds.groupby("time"):
        for i, (_t, _ds) in enumerate(ds.groupby("time")):
            hlpr.ax.set_title(
                title_fstr.format(time=_t.item()), **title_kwargs
            )
@@ -119,6 +110,14 @@ def agents_in_domain(
                _ds, hlpr=hlpr, collection=collection, **plot_kwargs
            )

            if i == 0 and add_colorbar:
                cm.create_cbar(
                    collection,
                    fig=hlpr.fig,
                    ax=hlpr.ax,
                    **(cbar_kwargs if cbar_kwargs else {}),
                )

            # Done with this frame; yield control to the animation framework
            # which will grab the frame...
            yield
+4 −5
Original line number Diff line number Diff line
@@ -13,11 +13,10 @@
    source: &color_source orange            # 3
    stone: &color_stone slategray           # 4

  cycler: &cycler 'cycler(
        "color",
        ["darkkhaki", "forestgreen", "firebrick", "orange", "slategray",]
    )'

  cycler: &cycler !format
    fstr: "cycler('color', ['{cmap[empty]:}', '{cmap[tree]:}', '{cmap[infected]:}', '{cmap[source]:}', '{cmap[stone]:}'])"
    cmap:
      <<: *cmap



+16 −7
Original line number Diff line number Diff line
@@ -3,6 +3,20 @@
.variables:
  base_path: &base_path  data/ForestFire

  # Colormap used throughout these plots
  # NOTE The order maps to the `kind` values from 0 .. 4
  cmap: &cmap
    empty: &color_empty   darkkhaki
    tree: &color_tree     forestgreen
    ' ': none  # not used in FFM
    source: &color_source orange
    stone: &color_stone   slategrey

  cycler: &cycler !format
    fstr: "cycler('color', ['{cmap[empty]:}', '{cmap[tree]:}', '{cmap[ ]:}', '{cmap[source]:}', '{cmap[stone]:}'])"
    cmap:
      <<: *cmap




@@ -200,7 +214,7 @@ tree_density:
      y: [0., 1.]

  # Passed on to plt.plot
  # ...
  color: *color_tree


# .. Facet grid ...............................................................
@@ -369,12 +383,7 @@ ca/forest:
  to_plot:
    kind:
      title: Forest State
      cmap:
        empty: darkkhaki
        tree: forestgreen
        ' ': none  # not used in FFM
        source: orange
        stone: slategrey
      cmap: *cmap

# ... The forest age ..........................................................
ca/forest_age:
+9 −3
Original line number Diff line number Diff line
@@ -5,6 +5,11 @@
.variables:
  base_path: &base_path data/GameOfLife

  # The discretized colormap used here, mapping to states 0 and 1, respectively
  cmap: &cmap
    empty: &color_empty     white
    living: &color_living   cornflowerblue



# =============================================================================
@@ -62,9 +67,8 @@ ca/state:
    living:
      title: " "
      add_colorbar: false
      cmap:
        empty: white
        living: cornflowerblue
      cmap: *cmap



# The mean density of living cells
@@ -92,3 +96,5 @@ density_living_cells:
    set_labels:
      y: Density of living cells
      only_label_outer: true

  color: *color_living
+5 −3
Original line number Diff line number Diff line
@@ -6,7 +6,8 @@
  model_name: &model_name PredatorPrey
  base_path: &base_path data/PredatorPrey

  colors: &colors
  # Colors used throughout these plots
  cmap: &cmap
    empty: &color_empty white
    predator: &color_predator '#FFCC66'
    prey: &color_prey '#006666'
@@ -129,8 +130,8 @@ species_densities:

  style: &color_cycler
    axes.prop_cycle: !format
      fstr: "cycler('color', ['{colors[predator]:}', '{colors[prey]:}'])"
      colors: *colors
      fstr: "cycler('color', ['{cmap[predator]:}', '{cmap[prey]:}'])"
      cmap: *cmap

# -- Time series of the predator and prey resources ---------------------------
mean_resources:
@@ -256,6 +257,7 @@ population:
        both: *color_both           # 3



# --- More detailed animation: prey only, combined, predator only -------------
population_detailed:
  based_on:
Loading