Matplotlib y-tick标签未显示

时间:2017-11-29 21:21:46

标签: python python-3.x matplotlib

出于某种原因,y-tick和y-tick标签没有显示在我的情节上。变量data是一个pandas数据帧:rfr_scatter = pd.DataFrame({'Actual':y_test, 'Model Predicted':rfr_predictions})

import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import matplotlib.animation as animation
from matplotlib import style
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
import tkinter as tk
from tkinter import *

def ScatterPlotter(notebooktab, data, test, pred):
    f = Figure(figsize=(7,5), dpi=100)
    ax1 = f.add_subplot(111, title="Model Performance")

    for item in ([ax1.title, ax1.xaxis.label, ax1.yaxis.label] +
                 ax1.get_xticklabels() + ax1.get_yticklabels()):
        item.set_fontsize(8)
        item.set_color('black')

    markersize = 0.8
    alpha = 0.05

    line = np.arange(min(test), min(test) + 35, 5)
    data.plot.scatter(x='Actual', y='Model Predicted', ax=ax1, s=markersize, alpha=alpha)
    ax1.set_xlim((min(test),max(test)))
    ax1.set_ylim((pred.min(),pred.max()))
    ax1.plot(line,line,clr_red,'--', label = "Perfect")

    canvas = FigureCanvasTkAgg(f, notebooktab)
    canvas.show()
    canvas.get_tk_widget().pack() 

我明白了: enter image description here

我已经尝试将yticks设置为可见,没有运气。我可能错过了一些简单的事情......

编辑:删除ax1.set_ylim((pred.min(),pred.max()))在图表上给我一些标记,它几乎看起来像标签在文本上,或文本没有完成渲染。

enter image description here

1 个答案:

答案 0 :(得分:0)

ax1.plot(line,line,clr_red,'--', label = "Perfect")更改为ax1.plot(line,line,'r--', label = "Perfect")解决了问题