【发布时间】:2015-07-03 17:27:45
【问题描述】:
我将 Qt5 后端用于 matplotlib,并尝试在 FigureCanvas 中嵌入绘图。现在我在将带有 pcolormesh 的大型矩阵绘制到图形的轴对象中时遇到了问题。不知何故,生成的 QuadMesh 不会填充整个轴,而是在网格上方和右侧留下空间。
第二个问题是 x 轴标签没有旋转,尽管我调用了 autofmt_xdata()。以下是相关代码:
class MyCanvas(FigureCanvas):
def __init__(self, parent=None):
self.figure = Figure()
self.figure.set_tight_layout(True)
self.matrix_axes = self.figure.add_subplot(111)
divider = make_axes_locatable(self.matrix_axes)
self.color_axes = divider.append_axes("right", size=0.1, pad=0.05)
self.matrix_axes.hold(False)
self.color_axes.hold(False)
def build_connectivity_matrix(self, source_neurons, target_neurons):
# plot the data,
# data is a 2d numpy array
color_mesh = self.matrix_axes.pcolormesh(data, cmap=color_map)
# add tick labels
self.matrix_axes.set_yticklabels(labels_y)
self.matrix_axes.set_xticklabels(labels_x)
self.figure.autofmt_xdate(rotation=30) # rotate x axis labels to fit more
# plot color bar
colorbar = self.figure.colorbar(color_mesh, cax=self.color_axes, orientation='vertical')
canvas = MyCanvas()
canvas.build_connectivity_matrix()
有什么想法吗?
【问题讨论】:
标签: python matplotlib pyqt5