haneulkim
haneulkim

Reputation: 4928

Increasing tick size by using axes in matplotlib

I am trying to create two axes within one figure

fig, ax = plt.subplots(2,figsize=(20,16))

This is my first figure:

ax[0].scatter(x,y, color="brown", alpha=0.4, s=200)
ax[0].plot(x,lof, color="brown", alpha=0.4)

for the first axes I want to make the x_ticks and y_ticks bigger how can I go about this?

Upvotes: 2

Views: 6733

Answers (3)

gmds
gmds

Reputation: 19885

If you don't need to differentiate between the X and Y axes, or major and minor ticks, use tick_params:

tick_size = 14

ax.tick_params(size=tick_size)

If you want to change the size of the tick labels, then you want this:

label_size = 14

ax.tick_params(labelsize=label_size)

Upvotes: 1

Diego Gallegos
Diego Gallegos

Reputation: 1752

You can use tick_params:

import matplotlib.pyplot as plt

fig, ax = plt.subplots(2,figsize=(6, 4))

ax[0].scatter([1,2,3],[1,2,3], color="brown", alpha=0.4, s=200)
ax[0].tick_params(width=2, length=4)
ax[1].tick_params(width=3, length=6)
ax[1].plot([1,2,3],[1,2,3], color="brown", alpha=0.4)

Plots

With it you can change all appearance properties of it. Here are the docs:

https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.tick_params.html

Upvotes: 3

Sheldore
Sheldore

Reputation: 39042

One way is to iterate over the major x- and y-ticks of the desired subplot (ax[0] here) and changing their font size.


Minimal representative answer

import matplotlib.pyplot as plt

fig, ax = plt.subplots(2,figsize=(8, 4))

ax[0].scatter([1,2,3],[1,2,3], color="brown", alpha=0.4, s=200)
ax[1].plot([1,2,3],[1,2,3], color="brown", alpha=0.4)

for tick in ax[0].xaxis.get_major_ticks():
    tick.label.set_fontsize(16)
for tick in ax[0].yaxis.get_major_ticks():
    tick.label.set_fontsize(16)
plt.tight_layout()
plt.show()

enter image description here

Upvotes: 1

Related Questions