繁体   English   中英

当值设置为对数 plot 时,Y_axis 刻度堆叠

[英]Y_axis ticks stacking when values are set in logarithmic plot

我正在尝试 plot 散布 plot 与对数 y 轴(像这样,但 y 轴是对数)。 在我更改 y 刻度值之前,我能够让 plot 正常工作,但是一旦我将值更改为我想要的值,plot 就会以错误的比例结束。 我在使用 tkinter 制作的 GUI 上显示 plot。 我错过了什么? 任何帮助将不胜感激。

我正在使用的代码:

    x=np.array (x_values)
    y= np.array (y_values)
    
    fig = Figure(figsize=(6,6))
    a = fig.add_subplot(111)
    a.scatter(x,y,color='red')
   
    a.set_title ("Estimation Grid", fontsize=16)
    a.set_ylabel("Y", fontsize=14)
    a.set_xlabel("X", fontsize=14)
    
    a.set_yscale("log")
    #a.set_yticks([100, 50, 10, 1.5, 1, 0.5, 0.1, 0.01, 0])
    a.set_yticks([0, 0.01, 0.1, 0.5, 1, 1.5, 10, 50, 100])
    a.get_yaxis().set_major_formatter(matplotlib.ticker.LogFormatter())
    a.grid()

生成的 plot: 在此处输入图像描述

用于此 plot 的值为:

x_values =[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]

y_values = [99.99, 75, 60, 50, 45, 40, 35, 30]

我看过的问题: 在对数图中重叠轴刻度标签设置刻度与对数刻度

不要在日志 plot 的 yticks 中包含零。 由于 log(0) 是负无穷大,所以刻度 0 和刻度 0.01 之间的距离会太大。 您可以为最小的 y 选择另一个小的但正值,例如 0.0001,具体取决于您的数据

JohanC 在上面的评论中回答了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM