【问题标题】:Y_axis ticks stacking when values are set in logarithmic plot在对数图中设置值时,Y 轴刻度堆叠
【发布时间】:2020-09-05 18:34:21
【问题描述】:

我正在尝试使用对数 y 轴(Like this 但 y 轴为对数)绘制散点图。在更改 y 刻度值之前,我能够使绘图正常工作,但是一旦我将值更改为我希望的值,绘图就会以错误的比例结束。我正在使用 tkinter 制作的 GUI 上显示该图。我错过了什么?任何帮助将不胜感激。

我正在使用的代码:

    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()

结果图:

用于该图的值是:

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]

我看过的问题: Overlapping axis tick labels in logarithmic plots set ticks with logarithmic scale

【问题讨论】:

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

标签: python matplotlib tkinter plot


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-14
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    相关资源
    最近更新 更多