The overlay point on top of the filled contour section adds a lot of free space

I have the following Python code that I use to build a filled path:

def plot_polar_contour(values, azimuths, zeniths): theta = np.radians(azimuths) zeniths = np.array(zeniths) values = np.array(values) values = values.reshape(len(azimuths), len(zeniths)) r, theta = np.meshgrid(zeniths, np.radians(azimuths)) fig, ax = subplots(subplot_kw=dict(projection='polar')) ax.set_theta_zero_location("N") ax.set_theta_direction(-1) cax = ax.contourf(theta, r, values, 30) autumn() cb = fig.colorbar(cax) cb.set_label("Pixel reflectance") show() 

This gives me a plot like:

enter image description here

However, when I add the line ax.plot(0, 30, 'p') just before show() , I get the following:

enter image description here

It seems like just adding that one point (which is within the original axis range) spins the axis range on the radius axis.

Is it by design, or is it a mistake? What would you advise to do to fix this? Do I need to manually adjust the ranges of the axes, or is there a way to stop this additional command from executing?

+4
source share
1 answer

If the axis autoscaling mode is not explicitly specified, plot will use β€œfree” autoscaling, and contourf will use β€œtight” autoscaling.

The same thing happens for non-polar axes. For instance.

 import matplotlib.pyplot as plt import numpy as np plt.imshow(np.random.random((10,10))) plt.plot([7], [7], 'ro') plt.show() 

You have several options.

  • Explicitly call ax.axis('image') or ax.axis('tight') at some point in the code.
  • Go to scalex=False and scaley=False as the keyword arguments in plot .
  • Manually set the axis limits.

The simplest and most readable is simply to call ax.axis('tight') , imo

+5
source

Source: https://habr.com/ru/post/1397630/


All Articles