Make part of a matplotlib title bold and a different color

前端 未结 3 1593
滥情空心
滥情空心 2020-11-29 11:18

I would like to change part of a title to be bold. For example:

plt.title(\"This is title number: \" + str(number))

Given a title like the

相关标签:
3条回答
  • 2020-11-29 11:37

    This post should answer your question on manipulating the title. You can use latex text rendering and call textbf for that particular part of the string.

    Styling part of label in legend in matplotlib

    Here is the documentation: http://matplotlib.org/users/usetex.html http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.set_title

    0 讨论(0)
  • 2020-11-29 11:39

    From matplotlib version 2 on, there is no need to use latex (which would require a working latex installation). One can use normal MathText to render part of the title in bold.

    import matplotlib.pyplot as plt
    number = 2017
    plt.title("This is title number: " + r"$\bf{" + str(number) + "}$")
    plt.show()
    

    0 讨论(0)
  • 2020-11-29 11:43

    activate latex text rendering

    from matplotlib import rc
    rc('text', usetex=True)
    
    plt.title("This is title number: " + r"\textbf{" + str(number) + "}")
    
    0 讨论(0)
提交回复
热议问题