Matplotlib显示一个轴而没有数据

时间:2015-01-31 01:32:08

标签: python matplotlib pyqt4

我想只显示一个数字的x轴,并在下面绘制另一个数字绘制数据(较低的一个具有与顶部绘图相同的x轴值但不显示任何刻度或标签)。

我还没有看到任何改变实际绘图尺寸的文档,只有图形尺寸。

下面的代码提供了一些想法,但我希望顶部的图表只显示一条水平线和x值,y轴应该没有维度。通过设置subplots_adjust我可以让y轴尽可能接近零,但设置底部任何大(底部= 0.9我得到一个ValueError(底部不能是> =顶部)

from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QSizePolicy
import sys

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
import numpy as np

qapp = QtGui.QApplication(sys.argv)
qWidget = QtGui.QWidget()
qWidget.setGeometry(QtCore.QRect(0, 0, 400, 400))
hBoxLayout = QtGui.QHBoxLayout(qWidget)
qWidget.setLayout(hBoxLayout)

qScroll = QtGui.QScrollArea(qWidget)
qScroll.setGeometry(QtCore.QRect(0, 0, 400, 400))
qScroll.setFrameStyle(QtGui.QFrame.NoFrame)
qScroll.setVisible(True)
hBoxLayout.addWidget(qScroll)

qScrollContents = QtGui.QWidget()
qScrollLayout = QtGui.QVBoxLayout(qScrollContents)
qScrollLayout.setGeometry(QtCore.QRect(0, 0, 800, 800))

qScroll.setWidget(qScrollContents)
qScroll.setWidgetResizable(True)

qFigWidget1 = QtGui.QWidget(qScrollContents)
fig1 = Figure(figsize=(5.0, 1.0), dpi=100)
canvas = FigureCanvas(fig1)
canvas.setParent(qFigWidget1)
canvas.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)

ax1 = fig1.add_subplot(111)
x = np.arange(0, 10.0, 0.1)
yData = np.zeros(100)  
ax1.plot(x, yData)
ax1.set_ylim(0, 0)
ax1.get_xaxis().tick_bottom() 
ax1.axes.get_yaxis().set_visible(False)
fig1.subplots_adjust(bottom=0.85)

plotLayout = QtGui.QVBoxLayout()
plotLayout.addWidget(canvas)
qFigWidget1.setLayout(plotLayout)
qScrollLayout.addWidget(qFigWidget1)

qFigWidget2 = QtGui.QWidget(qScrollContents)
fig2 = Figure(figsize=(5.0, 5.0), dpi=100)
canvas = FigureCanvas(fig2)
canvas.setParent(qFigWidget2)
canvas.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)

ax2 = fig2.add_subplot(111)
x = np.arange(0, 10.0, 0.1)
ax2.plot(x, x*x)
ax2.axes.get_xaxis().set_visible(False)

plotLayout = QtGui.QVBoxLayout()
plotLayout.addWidget(canvas)

qFigWidget2.setLayout(plotLayout)
qScrollLayout.addWidget(qFigWidget2)
qScroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
qScroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)

qScrollContents.setLayout(qScrollLayout)

qWidget.show()
exit(qapp.exec_()) 

0 个答案:

没有答案