0
import numpy as np
import matplotlib.pyplot as plt
from sampleLibrary import sample
fig, ax = plt.subplots(figsize=plt.figaspect(1))
X, Y = np.meshgrid(np.arange(-180, 180, 4), np.arange(-180, 180, 4))
Z = np.load(sample) 
ax.set(xticks=range(-180, 180, 60), yticks=range(-180, 180, 60))
ax.xaxis.set_major_formatter(StrMethodFormatter(u"{x:.0f} °"))
ax.yaxis.set_major_formatter(StrMethodFormatter(u"{x:.0f} °"))
ax.contourf(X,Y,Z, levels=levels, colors=colors)
plt.xlabel("Φ")
plt.ylabel("Ψ")

The above code does not show me a graph from -180 degree to 180 degree but instead only till 120 degree. I tried with numbers>180 but the result stays the same.

  • 1
    `range` is exclusive - try `list(range(-180, 181, 60))` which outputs `[-180, -120, -60, 0, 60, 120, 180]`. (Note 181 instead 180). – Jeppe Apr 12 '22 at 20:09
  • In general, `np.linspace()` is preferable over `np.arange()`. I spent once several days debugging code because due to [float point problems](https://stackoverflow.com/q/588004/8881141), np.arange() sometimes did not land on the expected end point. – Mr. T Apr 13 '22 at 08:04

0 Answers0