This question already has answers here:
How to change legend size with matplotlib.pyplot
                                
                                    (6个答案)
                                
                        
                                3年前关闭。
            
                    
这是我的代码

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


我应该如何设置标签?

最佳答案

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

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

关于python - 如何设置ax.legend fontsize? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35652711/

10-12 16:52