0

I am trying to set two different limits in my plot but i am not getting any success. For a single range I know i can use simply plt.yticks(min_range,max_range,step=x), this will give me a plot with x difference between each tick, But what i want is,plt.yticks((0,2,step=0.1),(2,max_range,step=2)), So That On my plot i want to have ticks of difference 0.1 between 0 and 2 and after that the step size of 2. Any Help on this Please!

1 Answer 1

4

You can generate such customized tick values using two arrays with different spacing. You can then merge them (concatenate) to get a single array and then assign them to plt.yticks(). Although the output on the y-axis is hard to read but that's for you to sort out how to make it more readable. Below is a simple example:

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 7, 100)
y = x
tick1 = np.arange(0,2, 0.1)

tick2 = np.arange(2, 8, 2)
yticks = np.concatenate((tick1, tick2))

plt.plot(x, y)
plt.yticks(yticks);
plt.show()

enter image description here

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

3 Comments

Thank You very much, though didn't look like what I was expecting, but will work for me :)
@Rizwan: Instead of 0.1, you can use 0.2 spacing to make it look better
I did :)... And i am using tick of 0.5, and for upper limit i increased the tick difference. Anything lower than 0.3 was not understandable... Thanks :)

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.