我有一个使用嵌入到pyQT GUI中的matplotlib图,因此我需要回收图来显示几个结果。
然而,当我清除这个数字并绘制一个系列时,我得到了这个: 而不是这个: 如果我在没有显示矩阵的情况下绘制系列,我得到了。
因此,重现问题的脚本是:
from matplotlib.pyplot import figure, show
import numpy
fig = figure()
ax = fig.add_subplot(111)
mat = numpy.random.randn(20, 20)
# display the matrix
ax.spy(mat, markersize=5)
x = numpy.linspace(0, 1, 100)
y = x**2 + x - 5
ax.clear()
ax.plot(x, y)
我也试过
ax.relim() # make sure all the data fits
ax.autoscale() # auto-scale
但它并没有做任何明显的事情。
答案 0 :(得分:0)
plt.spy
会自动将轴的纵横比设置为'equal'
,以确保方形矩阵的稀疏图看起来是方形的。如果系列的x轴刻度远大于y轴的x轴刻度,则相等的纵横比将产生非常长而细的线图。
切换回'默认'在自动确定宽高比的模式下,您可以拨打ax.set_aspect('auto')
:
from matplotlib.pyplot import figure, show
import numpy
fig = figure()
ax = fig.add_subplot(111)
mat = numpy.random.randn(20, 20)
# display the matrix
ax.spy(mat, markersize=5)
x = numpy.linspace(0, 1, 100)
y = x**2 + x - 5
ax.clear()
ax.set_aspect('auto')
ax.plot(x, y)