Home > Blockchain >  increasing font size of ticks
increasing font size of ticks

Time:07-01

i have a simple x,y plot that i want to increase the font of of ticks on x and y axes, so that they match the font size of x,y labels - fontsize=30. i also need to change the spacing on both axes so that they look more or less like the picture below, although the data sets are different.

thanks in advance.

wished plot

my plot

my code:

import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
x = [1.53,0.84,0.7,0.6,0.53,0.47,0.38,0.35]
y = [19.64,14.33,11.25,7.58,2.84,0.87,0.36,0]
plt.plot(x, y, marker="o")

plt.xlabel(r'Grid spacing $\AA$', fontsize=20)
plt.ylabel('% error', fontsize=20)
plt.title('Protein solvation', fontsize=20)
plt.gca().invert_xaxis()

plt.show()

CodePudding user response:

plt.xticks(fontsize=20)
plt.yticks(fontsize=20)

enter image description here


You can also use these functions to set the tick positions and labels:
plt.xticks(x, map(lambda x: f'{x:.2f}', x), fontsize=20, rotation=90)
plt.yticks([0, 10, 20], ['0', '10', '20'], fontsize=20)

enter image description here (plotted with plt.figure(figsize=(12,6)))

  • Related