使用Python我需要每64个字符在字符串中插入换行符.在Perl中很简单:
s/(.{64})/$1\n/
Run Code Online (Sandbox Code Playgroud)
如何使用Python中的正则表达式来完成?有更多的pythonic方式吗?
我有一个很长的字符串作为 xticks 的 matplotlib boxplot。有没有办法自动将它们分成多行以使情节更干净?我正在使用 seaborn 函数barplot来创建图形。
我用来创建它的代码:
plt.figure(figsize=(15,13))
sns.barplot(x="Component",y="TTTR",color = "C0",data=new,dodge=False,edgecolor="black",zorder=3)
plt.xticks(rotation=90)
plt.grid(axis='y',zorder=0)
plt.title("10 most impactful components",size=30,y=1.04,**pfont)
plt.ylabel("Impact (Sum TTR in h)")
plt.xlabel('Component')
plt.tight_layout()
Run Code Online (Sandbox Code Playgroud)