【问题标题】:How to set ax.legend fontsize? [duplicate]如何设置 ax.legend 字体大小? [复制]
【发布时间】:2016-06-09 17:27:14
【问题描述】:

这是我的代码

import os,sys
import Image
import matplotlib.pyplot as plt
from matplotlib.pyplot import *
from matplotlib.font_manager import FontProperties

jpgfile = Image.open("t002.jpg")

# Set up the figure and axes.
fig = plt.figure(figsize=(18,10))  # ...or whatever size you want.
ax = fig.add_subplot(111)
ax.legend(fontsize=18)
# Draw things.
plt.imshow(jpgfile)  # Unlike plot and scatter, not a method on ax.
ax.set_xlabel('normalized resistivities')
ax.set_ylabel('normalized velocities')
ax.set_xticks([]); ax.set_yticks([])

# Save and show.
plt.savefig("fig.jpg")
plt.show()

但是

/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_axes.py:519: UserWarning: No labelled objects found. Use label='...' kwarg on individual plots

我应该如何设置标签?

【问题讨论】:

  • 在我看来这不是一个重复的问题。

标签: python matplotlib


【解决方案1】:

Legend 字体是通过向 'prop' kwarg 提供字体属性值对的字典来定制的:

ax.legend(prop=dict(size=18))

【讨论】:

    猜你喜欢
    • 2012-05-04
    • 2012-05-22
    • 2015-02-08
    • 2020-12-07
    • 2018-01-09
    • 2011-03-04
    • 2020-03-01
    • 2020-06-12
    相关资源
    最近更新 更多