Vertical line axvline plots line in wrong position in loglog plot in matplotlib

坚强是说给别人听的谎言 提交于 2019-12-24 04:09:07

问题


I have a problem using axvline to plot vertical lines in the loglog plot of matplotlib.

The first problem is that the vertical lines do not appear at the right location.

The second problem, possibly related is that when I zoom in or translate the plot, the vertical lines just stay in place and are not appropriately transformed by the translation (sliding the plot) or zooming into to the plot.

My code looks as follows:

import numpy as np
import matplotlib.pyplot as plt

f, axes = plt.subplots(1, sharex=True, sharey=True)

axes.loglog(frqs,F_in,label="Input")
axes.loglog(frqs,F_out,label="Output")
axes.autoscale(enable=True, axis='x', tight=True) 
axes.set_title("Input and Output Spectrum")
axes.legend()

axes.axvline(x=0.01, color='k')

Unfortunately the black/grey vertical line does not show up at 0.01 but somewhere between 0.01 and 0.1 (the other vertical lines are also not in the right location):

In addition, now if I zoom into the image, the data is zoomed appropriately but the vertical lines are left unchanged.

Additional Info:

  • Matplotlib 1.5.1
  • Python 3.5.1
  • ipython-notebook 4.0.4
  • mpld3

I tried upgrading to matplotlib 1.5.3 but that leaves the problem unchanged.

来源:https://stackoverflow.com/questions/39827697/vertical-line-axvline-plots-line-in-wrong-position-in-loglog-plot-in-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!