diff --git a/cirq-core/cirq/experiments/qubit_characterizations.py b/cirq-core/cirq/experiments/qubit_characterizations.py index 916c662e468..b5a4c754f76 100644 --- a/cirq-core/cirq/experiments/qubit_characterizations.py +++ b/cirq-core/cirq/experiments/qubit_characterizations.py @@ -105,7 +105,7 @@ def plot(self, ax: Optional[plt.Axes] = None, **plot_kwargs: Any) -> plt.Axes: The plt.Axes containing the plot. """ show_plot = not ax - if not ax: + if ax is None: fig, ax = plt.subplots(1, 1, figsize=(8, 8)) # pragma: no cover ax.set_ylim((0.0, 1.0)) # pragma: no cover ax.plot(self._num_cfds_seq, self._gnd_state_probs, 'ro', label='data', **plot_kwargs) diff --git a/cirq-core/cirq/linalg/decompositions.py b/cirq-core/cirq/linalg/decompositions.py index 5c51cd79698..15658aa15fb 100644 --- a/cirq-core/cirq/linalg/decompositions.py +++ b/cirq-core/cirq/linalg/decompositions.py @@ -629,7 +629,7 @@ def scatter_plot_normalized_kak_interaction_coefficients( >>> plt.show() """ show_plot = not ax - if not ax: + if ax is None: fig = plt.figure() ax = cast(mplot3d.axes3d.Axes3D, fig.add_subplot(1, 1, 1, projection='3d')) diff --git a/cirq-core/cirq/vis/heatmap.py b/cirq-core/cirq/vis/heatmap.py index e496bacc014..70d8d1a6e8f 100644 --- a/cirq-core/cirq/vis/heatmap.py +++ b/cirq-core/cirq/vis/heatmap.py @@ -296,7 +296,7 @@ def plot( is plotted on. ``collection`` is the collection of paths drawn and filled. """ show_plot = not ax - if not ax: + if ax is None: fig, ax = plt.subplots(figsize=(8, 8)) original_config = copy.deepcopy(self._config) self.update_config(**kwargs) @@ -413,7 +413,7 @@ def plot( is plotted on. ``collection`` is the collection of paths drawn and filled. """ show_plot = not ax - if not ax: + if ax is None: fig, ax = plt.subplots(figsize=(8, 8)) original_config = copy.deepcopy(self._config) self.update_config(**kwargs) diff --git a/cirq-core/cirq/vis/state_histogram.py b/cirq-core/cirq/vis/state_histogram.py index d2525c06687..2a47693fc85 100644 --- a/cirq-core/cirq/vis/state_histogram.py +++ b/cirq-core/cirq/vis/state_histogram.py @@ -85,7 +85,7 @@ def plot_state_histogram( The axis that was plotted on. """ show_fig = not ax - if not ax: + if ax is None: fig, ax = plt.subplots(1, 1) if isinstance(data, result.Result): values = get_state_histogram(data) diff --git a/cirq-google/cirq_google/engine/calibration.py b/cirq-google/cirq_google/engine/calibration.py index dfbe73e467d..1df47e81e8e 100644 --- a/cirq-google/cirq_google/engine/calibration.py +++ b/cirq-google/cirq_google/engine/calibration.py @@ -275,7 +275,7 @@ def plot_histograms( ValueError: If the metric values are not single floats. """ show_plot = not ax - if not ax: + if ax is None: fig, ax = plt.subplots(1, 1) if isinstance(keys, str): @@ -320,7 +320,7 @@ def plot( values are not single floats. """ show_plot = not fig - if not fig: + if fig is None: fig = plt.figure() axs = cast(List[plt.Axes], fig.subplots(1, 2)) self.heatmap(key).plot(axs[0]) diff --git a/docs/dev/plotting.md b/docs/dev/plotting.md index 9243a17c6a9..6e51d0a2a73 100644 --- a/docs/dev/plotting.md +++ b/docs/dev/plotting.md @@ -35,7 +35,7 @@ class Foo: ... def plot(self, ax: Optional[plt.Axes]=None, **plot_kwargs: Any) -> plt.Axes: show_plot = not ax - if not ax: + if ax is None: fig, ax = plt.subplots(1, 1) # or your favorite figure setup # Call methods of the ax instance like ax.plot to plot on it. ... @@ -81,7 +81,7 @@ class Foo: def plot(self, axes: Optional[List[plt.Axes]]=None, **plot_kwargs: Any) -> List[plt.Axes]: show_plot = not axes - if not axes: + if axes is None: fig, axes = plt.subplots(1, 2) # or your favorite figure setup elif len(axes) != 2: # your required number of axes raise ValueError('your error message')