首页 > 解决方案 > 为什么我的 xlabel、ylabel 和 title 在散点图后没有显示?

问题描述

我正在用 Python 设置一个过滤工具。我想根据其他数据绘制一些数据,但我的散点图遇到了问题。实际上,显示的是数据,而不是图形标题、x 轴标签或 y 轴标签。有人可以解释我的错误吗?先感谢您。

x_text = str(self.comboBox1.currentText())
y_text = str(self.comboBox2.currentText())

x_data = self.data.getData(x_text)
y_data = self.data.getData(y_text)

if x_data is not None and y_data is not None : 
    if x_text =="Cycles":
        fig, ax = plt.subplots()
        ax = plt.subplot(111, facecolor= "lightgrey")
        for x,y in zip(x_data, y_data):
            if isinstance(y, list):
                ax.scatter([x]*len(y),y,marker = 'o',color="chocolate")
            else:
                ax.scatter(x,y,marker = 'o', color="teal")
        ax.set_title("Before filtering")
        #ax.set_xlabel(x_text)
        #ax.set_ylabel(y_text)
        ax.grid(True)
        fig.text(0.03,0.5 ,y_text, va='center', rotation = 'vertical', fontsize=12) #va : vertical alignement
        fig.text(0.5 ,0.03,x_text, ha='center',  fontsize=12)
        plt.show()

标签: pythonmatplotlibscatter

解决方案


推荐阅读