Home > front end >  is there any way to get the minor ticks data in matplotlib python
is there any way to get the minor ticks data in matplotlib python

Time:08-26

from matplotlib import pyplot as plt
from matplotlib.ticker import MultipleLocator
import numpy as np
import random
from numpy import random
weeks=np.arange(1,11)
cm = random.randint(10, size=(10))
plt.rcParams["figure.figsize"] = (15,10)
fig, ax = plt.subplots()
ax.grid(which='major', linestyle='-', linewidth='1', color='red')
ax.set_ylabel("cm")
ax.set_xlabel("weeks")
ax.minorticks_on()

plt.plot(weeks, cm)
ax.xaxis.set_minor_locator(MultipleLocator(1 / 9))
ax.yaxis.set_minor_locator(MultipleLocator(1 / 9))

ax.xaxis.set_minor_formatter(lambda x, pos: '123456789'[int(round(x * 9)) % 9])
ax.yaxis.set_minor_formatter(lambda x, pos: '123456789'[int(round(x * 9)) % 9])


ax.tick_params(axis='x', which='minor', labelsize=5)
ax.tick_params(axis='y', which='minor', labelsize=5)

ax.grid(True, which='both')
plt.xlim(1,10)
plt.ylim(1,10)
ax.yaxis.tick_right()
ax.yaxis.tick_left()

plt.plot(weeks, cm,marker='*', markersize=10, markeredgecolor='blue',)
print("Value of get_minorticklines() :",
ax.xaxis.get_minorticklines())
plt.vlines(weeks, 0, cm, linestyle="solid")
plt.hlines(cm, 0, weeks, linestyle="solid")
plt.show()

from the above code i plotted the graph like this [enter image description here] i plotted x and y data and i want to get the minor ticks data how to get it

CodePudding user response:

If you are interested in the positions of minor ticks on the y axis as they are you can use the following :

print(list(ax.yaxis.get_minorticklabels()))

CodePudding user response:

Hi Arash thanks for the response "print(list(ax.yaxis.get_minorticklabels()))" from this code i will get output like this enter image description here

i have small graph with x lim 10 points and y lim 10 points with the same graph and i want the values for 100 sample points

  • Related