我有这个代码,我试图只将字符串的一部分加粗,而不是整个图例字符串。我怎样才能做到这一点?
我曾尝试使用 "\033[1m" (start) 和 "\033[0;0m" (end) 以及 plt.legend(prop=dict(weight='bold'),但同样,这是大胆的整个字符串,但只是其中的一部分。这是一个例子:
import matplotlib
import matplotlib.pyplot as plt
plt.plot([1,2,3], [4,5,6])
plt.legend(['Test [bold]'])
plt.show()
Run Code Online (Sandbox Code Playgroud)
在第二组括号内,我希望“粗体”实际上是粗体,而不是“测试”。谢谢
我有一个列表,希望按特定顺序进行排序。我已经尝试了来自stackoverflow的各种方法,但它们并没有为我提供所需的答案。任何帮助,将不胜感激
order_list = ['ABC123'] #this is the list that should define the order, according to the first character
lst = ['AA2', 'A3', 'A1', 'AA1', 'BBB2', 'A2', 'AA3', 'BBB1', 'AAA', 'BBB3']
print(sort_method(lst))
>>>['AAA', 'AA1', 'AA2', 'AA3', 'A1', 'A2', 'A3', 'BBB1', 'BBB2', 'BBB3','CCC1','CCC2']
#different orderlist
order_list = ['CBA123']
lst = ['BBB3', 'AA2', 'A2', 'BBB2', 'CCC2', 'AA3', 'CCC1', 'AAA', 'AA1', 'A3', 'BBB1', 'A1']
print(sort_method(lst))
>>>['CCC1','CCC2','BBB1', 'BBB2', 'BBB3','AAA', 'AA1', 'AA2', 'AA3', 'A1', 'A2', 'A3']
Run Code Online (Sandbox Code Playgroud)