简体   繁体   English

调整 matplotlib RadioButtons 字体大小

[英]Adjust matplotlib RadioButtons font size

I wonder if anyone has an advice on how to adjust the font size on the RadiouButtons side text.我想知道是否有人对如何调整RadiouButtons侧文本的字体大小有建议。 Taking the widget example from matplotlib以 matplotlib 中的小部件为例

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import RadioButtons

t = np.arange(0.0, 2.0, 0.01)
s0 = np.sin(2*np.pi*t)
s1 = np.sin(4*np.pi*t)
s2 = np.sin(8*np.pi*t)

fig, ax = plt.subplots()
l, = ax.plot(t, s0, lw=2, color='red')
fig.subplots_adjust(left=0.3)

axcolor = 'lightgoldenrodyellow'
rax = fig.add_axes([0.05, 0.7, 0.15, 0.15], facecolor=axcolor)
radio = RadioButtons(rax, ('2 Hz', '4 Hz', '8 Hz'))


def hzfunc(label):
    hzdict = {'2 Hz': s0, '4 Hz': s1, '8 Hz': s2}
    ydata = hzdict[label]
    l.set_ydata(ydata)
    plt.draw()
radio.on_clicked(hzfunc)

rax = fig.add_axes([0.05, 0.4, 0.15, 0.15], facecolor=axcolor)
radio2 = RadioButtons(rax, ('red', 'blue', 'green'))


def colorfunc(label):
    l.set_color(label)
    plt.draw()
radio2.on_clicked(colorfunc)

rax = fig.add_axes([0.05, 0.1, 0.15, 0.15], facecolor=axcolor)
radio3 = RadioButtons(rax, ('-', '--', '-.', ':'))


def stylefunc(label):
    l.set_linestyle(label)
    plt.draw()
radio3.on_clicked(stylefunc)

plt.show()

在此处输入图像描述

How could I make "2Hz, 4Hz, 8Hz" larger?我怎样才能使“2Hz、4Hz、8Hz”变大?

It is possible to adjust the buttons size by accessing the Circle objects on the RadioButtons .可以通过访问RadioButtons上的Circle对象来调整按钮大小。 Is there something similar to the font size?有没有类似字体大小的东西? (the buttons widget have the .label.set_fontsize() attribute but I have not found a similar thing for this widget) 按钮小部件具有.label.set_fontsize()属性,但我没有为该小部件找到类似的东西)

In order to change the font size of the RadioButton labels you need to access the properties of the individual label:为了更改RadioButton标签的字体大小,您需要访问单个 label 的属性:

for r in radio.labels: r.set_fontsize(16)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM