0

I am trying to plot a scatter plot with a logarithmic y-axis (Like this but with the y-axis being logarithmic). I am able to get the plot to work properly before I change the y tick values, but as soon as I change the values to the ones I desire the plot ends up with the wrong scale. I am displaying the plot on a GUI made using tkinter. What am I missing? Any help would be greatly appreciated.

The code I am using:

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

The resulting plot: enter image description here

The values used for this plot are:

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]

Questions I've looked at: Overlapping axis tick labels in logarithmic plots set ticks with logarithmic scale

2
  • Don't include zero in your yticks for a log plot. As log(0) is minus infinity the distance between tick 0 and tick 0.01 will be much too large. You can choose another small but positive value for the smallest y, e.g. 0.0001, depending on your data. Commented May 19, 2020 at 16:05
  • That's it. Thank you. Commented May 19, 2020 at 16:27

1 Answer 1

0

Don't include zero in your yticks for a log plot. As log(0) is minus infinity the distance between tick 0 and tick 0.01 will be much too large. You can choose another small but positive value for the smallest y, e.g. 0.0001, depending on your data

Answered in the comment above by JohanC.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.