0

I used the parasite axis in python to plot three curves. The form of coordinates is like '5+1e7'. And the tick labels of the third y-axis and x-axis seem to be in the wrong place. As shown in the three pictures: the tick label '+1e7' of the x-axis is above the x-axis; tick labels of the secondary y-axis and third y-axis overlap ('+1e10'and'+1e8').

My code is as follows:

from mpl_toolkits.axisartist.parasite_axes import HostAxes, ParasiteAxes
import matplotlib.pyplot as plt

fig = plt.figure()

host = fig.add_axes([0.15, 0.1, 0.65, 0.8], axes_class=HostAxes)
par1 = ParasiteAxes(host, sharex=host)
par2 = ParasiteAxes(host, sharex=host)
host.parasites.append(par1)
host.parasites.append(par2)

host.axis["right"].set_visible(False)

par1.axis["right"].set_visible(True)
par1.axis["right"].major_ticklabels.set_visible(True)
par1.axis["right"].label.set_visible(True)

par2.axis["right2"] = par2.new_fixed_axis(loc="right", offset=(60, 0))

p1, = host.plot([1+1e7, 5+1e7, 10+1e7], [1+1e7, 5+1e7, 10+1e7])
p2, = par1.plot([1+1e7, 5+1e7, 10+1e7], [0+1e10, 3+1e10, 2+1e10])
p3, = par2.plot([1+1e7, 5+1e7, 10+1e7], [50+1e8, 30+1e8, 15+1e8])

host.set_xlabel("x")
host.set_ylabel("y1")
par1.set_ylabel("y2")
par2.set_ylabel("y3")

host.legend()

host.axis["left"].label.set_color(p1.get_color())
par1.axis["right"].label.set_color(p2.get_color())
par2.axis["right2"].label.set_color(p3.get_color())

plt.show()

Here's the results: enter image description here

I don't know how to solve this problem. I want the '+1e7' of the x-axis to be located in the bottom-right of the x-axis. Also, I want the '+1e8' of "y3" to be right above the y3-axis.

Keloyi
  • 1
  • I think [this answer](https://stackoverflow.com/questions/39620700/positioning-the-exponent-of-tick-labels-when-using-scientific-notation-in-matplo) will be helpful. – r-beginners Nov 05 '22 at 11:26

0 Answers0