'Matplotlib aspect ratio

I want to plot the attached plot Plot

such that its more clear, in order to plot it i used the code.,

from mpl_toolkits.axes_grid1 import host_subplot
import matplotlib.pyplot as plt
host = host_subplot(111)

par = host.twinx()

host.set_xlabel(r'$s$ (m) ', fontsize=14)
host.set_ylabel(r'$B_x B_y$ (m) ', fontsize=16)
#host.set_ylabel(r'$\beta_y[m]$')
par.set_ylabel(r'$\eta_x \eta_y$', fontsize=16)

p1, = host.plot(s_pos, betax, label=r'$\beta_x[m]$')
p2, = host.plot(s_pos, betay, label=r'$\beta_y[m]$')
p3, = par.plot(s_pos, dispersionx, label=r'$\eta_x[m]$')
p4, = par.plot(s_pos, dispersiony, label=r'$\eta_y[m]$')
leg = plt.legend()

host.yaxis.get_label().set_color(p1.get_color())
leg.texts[0].set_color(p1.get_color())

host.yaxis.get_label().set_color(p2.get_color())
leg.texts[1].set_color(p2.get_color())

par.yaxis.get_label().set_color(p3.get_color())
leg.texts[2].set_color(p3.get_color())

Now, i want to modify the aspect ration, so i used :

#set aspect ratio to .3
ratio = .3
x_left, x_right = plt.get_xlim()
y_low, y_high = plt.get_ylim()
plt.set_aspect(abs((x_right-x_left)/(y_low-y_high))*ratio)
#plt.title(plot_name)

plt.show()

Bu i got the error massage: " module 'matplotlib.pyplot' has no attribute 'get_xlim'"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source