消失的坐标轴,Python对数对数图

0 投票
1 回答
741 浏览
提问于 2025-04-17 21:11

我正在运行一个循环来绘制很多不同的线条,但用对数坐标图来绘制它们是最合适的(因为涉及到大约9个数量级)。在对数坐标图上,它们的绘制效果是正确的,但当我尝试用对数坐标图时,坐标轴和坐标轴标签却消失了。

#THIS IS FOR A NORMAL PLOT
import matplotlib.pyplot as plt

plt.figure()
for ii in list1:
    plt.plot(xarray[:], yarray[ii,:])
plt.show()

我尝试添加了以下内容:

plt.xscale('log')

还有

plt.yscale('log')

另外,我试过

plt.loglog(xarray[:], yarray[ii,:])
plt.semilogy(xarray[:], yarray[ii,:])

如果有人能帮帮我就太好了,我对绘图的经验不多,但我觉得让坐标轴显示出来应该很简单。谢谢。

这是我没有坐标轴的图

编辑:我还收到了以下错误信息。我刚刚重新安装了matplotlib,但仍然遇到同样的问题(可以绘图,但没有坐标轴)。

>Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py", line 1034, in draw
    func(*args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.py", line 2086, in draw
    a.draw(renderer)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axis.py", line 1093, in draw
    renderer)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axis.py", line 1042, in _get_tick_bboxes
    extent = tick.label1.get_window_extent(renderer)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/text.py", line 754, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/text.py", line 329, in _get_layout
    ismath=ismath)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 151, in get_text_width_height_descent
    self.mathtext_parser.parse(s, self.dpi, prop)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/mathtext.py", line 3009, in parse
    self.__class__._parser = Parser()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/mathtext.py", line 2193, in __init__
    - ((lbrace + float_literal + rbrace)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'

1 个回答

0

原来这个问题是跟之前看到的一个问题是同样的原因:在这个问题中

我彻底卸载了Python,然后重新安装了Python(适用于Mac OSX 10.3及以上的32位版本),还安装了matplotlib、scipy和numpy。现在坐标轴绘制得正确了。

撰写回答