Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

python - strange matplotlib resizing behavior

I'm embedding matplotlib in my PyQt 4 application and using it to display images. The matplotlib control is being displayed in a QDockWidget, and I'm setting some its parameters as follows:

imagePlot = self.axes.imshow(myNumpyArray, interpolation = "nearest")
imagePlot.axes.set_axis_off()
imagePlot.axes.get_xaxis().set_visible(False)
imagePlot.axes.get_yaxis().set_visible(False)
self.fig.subplots_adjust(bottom = 0, top = 1, left = 0, right = 1)

This has the desired effect i.e. the image is displayed filling as much space as possible in the QDockWidget while maintaining the aspect ratio. I can resize the dock widget by shrinking it horizontally and then expanding it and the image display is correct (filling as much space as possible while maintaining the aspect ratio). Now, if I add the following line:

imagePlot.axes.set(adjustable = "datalim")

I get unexpected behavior. Initially the image is displayed in the same manner as before, but after shrinking and expanding horizontally matplotlib seems to introduce a border around the data. For example, here's the image as it is displayed initially (and correctly):

Before size manipulation

And here's what matplotlib displays after I drag the side of the containing dock widget and shrink, then expand back to original size. Note the appearance of the border around the image.

enter image description here

What is causing this and how can I prevent it? Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...