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!
Add a comment
|
1 Answer
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()
3 Comments
Rizwan
Thank You very much, though didn't look like what I was expecting, but will work for me :)
Sheldore
@Rizwan: Instead of 0.1, you can use 0.2 spacing to make it look better
Rizwan
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 :)
