简体   繁体   English

如何调整括号大小并在matplotlib标签中部分设置标签的字体和大小?

[英]How to adjust parenthesis size and set font and size of the label partially in matplotlib labels?

I know the title does not make any sense. 我知道标题没有任何意义。 But, I tried to explain what I need here. 但是,我试图在这里解释我的需求。 I have a plot with the following labels. 我有一个带有以下标签的图。

plt.xlabel(r'$\tau^P_j$ (day)', fontsize=12)
plt.ylabel(r'$\rho(\{j\},k^*)$', fontsize=12)

For x label, I want to change the font of the text part to times new roman and font size to something smaller. 对于x标签,我想将文本部分的字体更改为新的罗马字体和较小的字体大小。 The function fontsize=12 applies to both the equation and the text parts in the label and the text part seems bigger than the math part, though they are both 12. 函数fontsize=12既适用于标签中的等式又适用于文本部分,尽管它们均为12,但文本部分似乎大于数学部分。

In addition, I need to adjust the size of the parenthesis in y label. 另外,我需要调整y标签中括号的大小。 The curly brackets appear much larger than the parenthesis. 大括号看起来比括号大得多。 I tried (r'$\\rho\\big(\\{j\\},k^*\\big)$', fontsize=12) , but no luck. 我尝试了(r'$\\rho\\big(\\{j\\},k^*\\big)$', fontsize=12) ,但是没有运气。 I am using Python 2.7. 我正在使用Python 2.7。

Things work fine for me in python 3.6.5 and matplotlib 2.2.2 . python 3.6.5matplotlib 2.2.2一切对我来说都很好。 I present below an answer to demonstrate the difference, both as axes labels and as texts (just to present y-label horizontally to notice the difference. 我在下面给出一个答案来说明差异,以轴标签和文本形式出现(只是为了水平显示y标签以注意差异)。

Minimal, Complete, and Verifiable example 最小,完整和可验证的示例

import matplotlib.pyplot as plt
from matplotlib import rc
rc('text', usetex=True)
plt.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]
fig = plt.figure(figsize=(6, 4))

x = range(6)
plt.plot(x, x)
plt.xlabel(r'$\tau^P_j$ $\text{\small{(day)}}$', fontsize=12)
plt.ylabel(r'$\rho\big(\{j\},k^*\big)$', fontsize=12)

plt.text(1,4, r'$\rho(\{j\},k^*)$', fontsize=12)
plt.text(1,3, r'$\rho\big(\{j\},k^*\big)$', fontsize=12)

plt.text(3,2, r'$\tau^P_j$ $\text{\small{(day)}}$', fontsize=12)
plt.text(3,1, r'$\tau^P_j$ (day)', fontsize=12)
plt.show()

在此处输入图片说明

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

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