0

In this plot

inclination = np.pi/6

def power(inclination,phi):
    h1=1.7 
    h2=0.5 
    D = np.arange(0.5, 12.0, 0.015)
    r = np.sqrt((h1-h2)**2 + D**2)
    freq = 865.7 
    lmb = 300/freq 
    H = D**2/(D**2+2*h1*h2)
    theta = 4*np.pi*h1*h2/(lmb*D)
    q_e = H**2*(np.sin(theta))**2 + (1 - H*np.cos(theta))**2
    sigma = 1.94
    N_1 = np.random.normal(0,sigma,D.shape)
    rnd = 10**(-N_1/10)
    F = 10 
    power=0.8
    R,PHI = np.meshgrid(r,phi[1:-1])
    alpha=inclination + np.arcsin((h1-h2)/R)
    gain=3.136*(np.tan(alpha)*np.sin(np.pi/2*np.cos(alpha)*np.sin(PHI)))**2
    y=10*np.log10( 1000*(power*gain*1.622*((lmb)**2) *0.5*1) / (((4*np.pi*R)**2) *1.2*1*F)*q_e*rnd )
    return (R,PHI,y)

phi=np.linspace(0, np.pi,num=787)
x,y,z = power(np.pi/4,phi)
import cmocean
cmap = cmocean.cm.oxy

I would like to take out the characters x10^0 of the x ticks labels and show 2,3, 4, 6 ... and 10. I have test a precedent post set ticks with logarithmic scale, but I cannot make it work and keep the colorbar of the heatmap.

EDIT

As suggested by @ImportanceOfBeingErnest, to plot the heatmap, I have changed the next lines

plt.contourf(x, y, z, 20, cmap=cmap)
cb=plt.colorbar();
plt.xlim(None, 12)
plt.ylim(0, np.pi)
plt.xlabel('Distance [m]', fontsize=12)
plt.ylabel('Phi [radians]', fontsize=12)
plt.xscale('log')

that plots this figure,

enter image description here

by this

fig1, ax1 = plt.subplots()
cs1 = ax1.contourf(x, y, z, 20, cmap=cmap)
fig1.colorbar(cs1,ax=ax1);
plt.xscale('log')
ax1.set_xlabel('Distance [m]', fontsize=12)
ax1.set_ylabel('Phi [radians]', fontsize=12)
#--- format y-labels in radians
y_pi   = y/np.pi
unit   = 0.25
y_tick = np.arange(0, 1 + unit, unit)
y_label = [r"$0$", r"$\frac{\pi}{4}$", r"$\frac{\pi}{2}$",  r"$3\frac{\pi}{4}$",   r"$\pi$"]
#y_label = [r"$" + format(r, ".2g")+ r"\pi$" for r in y_tick]
ax1.set_yticks(y_tick*np.pi)
ax1.set_yticklabels(y_label, fontsize=12)
#---

#--- x-labels removing the log format (i.e. 2x10^0 to 2)
ax1.set_xticks([2, 3, 4, 6, 10])
#ax1.get_xaxis().set_major_formatter(matplotlib.ticker.ScalarFormatter())
#ax1.get_xaxis().get_major_formatter().labelOnlyBase = False
ax1.set_xticklabels(["2", "3", "4", "6", "10"])

plots this figure,

enter image description here

which tests the solutions of set ticks with logarithmic scale and prints the desired labels but without removing the default log labels format.

user1993416
  • 698
  • 1
  • 9
  • 28

0 Answers0