Repository: yt-project/yt

Issue:
Messed up colorbars for phase plots in matplotlib 3
The following script:

```
import yt
ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
plot = yt.PhasePlot(ds.all_data(), 'density', 'temperature', 'cell_mass', weight_field=None)
plot.save()
```

Produces the following result in matplotlib 3.0.2 (as well as in 3.0.1 and 3.0.0):

![galaxy0030_2d-profile_density_temperature_cell_mass](https://user-images.githubusercontent.com/3126246/48962872-003c2380-ef55-11e8-9f5f-7fddc0551a74.png)

Whereas with matplotlib 2.2.3, I get:

![galaxy0030_2d-profile_density_temperature_cell_mass](https://user-images.githubusercontent.com/3126246/48962884-527d4480-ef55-11e8-9d67-d9523aa9fbe5.png)

Will try to make an example outside of yt that reproduces this behavior and report upstream to matplotlib...


Discussion:

Resolving patch:
diff --git a/yt/visualization/profile_plotter.py b/yt/visualization/profile_plotter.py
--- a/yt/visualization/profile_plotter.py
+++ b/yt/visualization/profile_plotter.py
@@ -49,6 +49,8 @@
     matplotlib_style_context, \
     iterable
 
+MPL_VERSION = LooseVersion(matplotlib.__version__)
+
 def get_canvas(name):
     from . import _mpl_imports as mpl
     suffix = get_image_suffix(name)
@@ -1089,7 +1091,7 @@ def _setup_plots(self):
 
             color = self._background_color[f]
 
-            if LooseVersion(matplotlib.__version__) < LooseVersion("2.0.0"):
+            if MPL_VERSION < LooseVersion("2.0.0"):
                 self.plots[f].axes.set_axis_bgcolor(color)
             else:
                 self.plots[f].axes.set_facecolor(color)
@@ -1117,10 +1119,16 @@ def _setup_plots(self):
             if self._cbar_minorticks[f] is True:
                 if self._field_transform[f] == linear_transform:
                     self.plots[f].cax.minorticks_on()
-                else:
-                    vmin = np.float64( self.plots[f].cb.norm.vmin )
-                    vmax = np.float64( self.plots[f].cb.norm.vmax )
-                    mticks = self.plots[f].image.norm( get_log_minorticks(vmin, vmax) )
+                elif MPL_VERSION < LooseVersion("3.0.0"):
+                    # before matplotlib 3 log-scaled colorbars internally used
+                    # a linear scale going from zero to one and did not draw
+                    # minor ticks. Since we want minor ticks, calculate
+                    # where the minor ticks should go in this linear scale
+                    # and add them manually.
+                    vmin = np.float64(self.plots[f].cb.norm.vmin)
+                    vmax = np.float64(self.plots[f].cb.norm.vmax)
+                    mticks = self.plots[f].image.norm(
+                        get_log_minorticks(vmin, vmax))
                     self.plots[f].cax.yaxis.set_ticks(mticks, minor=True)
             else:
                 self.plots[f].cax.minorticks_off()


Test patch:
diff --git a/tests/tests.yaml b/tests/tests.yaml
--- a/tests/tests.yaml
+++ b/tests/tests.yaml
@@ -47,7 +47,7 @@ answer_tests:
   local_owls_002:
     - yt/frontends/owls/tests/test_outputs.py
 
-  local_pw_025:
+  local_pw_026:
     - yt/visualization/tests/test_plotwindow.py:test_attributes
     - yt/visualization/tests/test_plotwindow.py:test_attributes_wt
     - yt/visualization/tests/test_particle_plot.py:test_particle_projection_answers