How to make the text size of x and y axis labels and title in matplotlib and prettyplotlib plots larger
I have set the size of the matplotlib or prettyplotlib plot figure to be large. For example, you can say that the size is 80 x 80 wide.
The size of the text for the plot title, x and y-axis labels (ie, label labels 2014-12-03 and axis labels [month of the year] become very small as long as they are unreadable.
How do I increase the size of these text labels? Now I have to zoom in with a web browser to see them.
+3
source to share
1 answer
Property size
:
import matplotlib.pyplot as plt
plt.xlabel('my x label', size = 20)
plt.ylabel('my y label', size = 30)
plt.title('my title', size = 40)
plt.xticks(size = 50)
plt.yticks(size = 60)
Example:
import numpy as np
import matplotlib.pyplot as plt
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75)
plt.xlabel('Smarts', size = 20)
plt.ylabel('Probability')
plt.title('Histogram of IQ', size = 50)
plt.text(60, .025, r'$\mu=100,\ \sigma=15$', size = 30)
plt.axis([40, 160, 0, 0.03])
plt.xticks(size = 50)
plt.yticks(size = 50)
plt.grid(True)
plt.show()
---------- EDIT --------------
using pretty plot
fig, ax = plt.plot()
fig.suptitle('fig title', size = 80)
ax.set_title('my title', size = 10)
ax.set_xlabel('my x label', size = 20)
ax.set_ylabel('my y label', size = 30)
for tick in ax.xaxis.get_major_ticks():
tick.label.set_fontsize(40)
for tick in ax.yaxis.get_major_ticks():
tick.label.set_fontsize(50)
--------- LEGEND --------------
use property prop
ppl.legend(prop={'size':20})
plt.legend(prop={'size':20})
the same command ..
Example:
import matplotlib.pyplot as plt
import matplotlib as mpl
from prettyplotlib import brewer2mpl
import numpy as np
import prettyplotlib as ppl
np.random.seed(12)
fig, ax = plt.subplots(1)
fig.suptitle('fig title', size = 80)
ax.set_title('axes title', size = 50)
for tick in ax.xaxis.get_major_ticks():
tick.label.set_fontsize(60)
ax.set_ylabel("test y", size = 35)
for i in range(8):
y = np.random.normal(size=1000).cumsum()
x = np.arange(1000)
ppl.plot(ax, x, y, label=str(i), linewidth=0.75)
ppl.legend(prop={'size':30})
fig.savefig('plot_prettyplotlib_default.png')
+5
source to share