0

I have be trying to reproduce the graph shown here: hplot As you can see, the x-axis is a log scale that contains only negative values. I have looked online for some tips. Most of them dealt with the symlog function of matplotlib which I'd rather not use since the function I am trying to plot is only defined on ]-inf, 0[. So I am asking for another suggestion. Also, I would like the x-axis to only have the three ticks shown on the attachment (i.e., -10^0, -10^-2, -10^-4). Any tip is welcomed! Thank you!

The code for the function is:

x = np.linspace(-1, -0.0001, 10000)

a = 2*np.log((1+(1-16*20*x)**0.25)/2) +np.log((1+((1-16*20*x)**0.25)**2)/2) - 2*np.arctan((1-16*20*x)**0.25) + np.pi/2

b = 2*np.log((1+(1-16*10*x)**0.25)/2) +np.log((1+((1-16*10*x)**0.25)**2)/2) - 2*np.arctan((1-16*10*x)**0.25) + np.pi/2

c = 2*np.log((1+(1-16*5*x)**0.25)/2) +np.log((1+((1-16*5*x)**0.25)**2)/2) - 2*np.arctan((1-16*5*x)**0.25) + np.pi/2

y = (np.log(20/5) - a + b)/(np.log(10/5) - c + b)

nalfahel
  • 145
  • 9

1 Answers1

0

You can plot y against -x in log scale and format the xticks accordingly:

from matplotlib.ticker import FuncFormatter
fig, ax = plt.subplots()
ax.plot(-x,y)
ax.set_xscale('log')
ax.invert_xaxis()
ax.set_xticks([1,1e-2,1e-4])
ax.xaxis.set_major_formatter(FuncFormatter(lambda x,pos: '$-\\mathdefault{10^{'+f'{int(np.log10(x))}'+'}}$'))

Output:

enter image description here

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
  • Hi! thank you so much for your reply! Could you please explain to me what the last line of code does? – nalfahel Nov 18 '20 at 05:12
  • @nalfahel basically the ticks are `1,1e-2,1e-4` and the last line of code labels the ticks with its negative values. – Quang Hoang Nov 18 '20 at 05:25