0

I tried to create text annotations in matplotlib using \n, on the plot instead of a line break it is showing a square box

 "Fault location:" + str(sc) + "\nI_sc=" + str(fault)

I wanted to Fault location and I_sc in separate line like

Fault location: 1
I_sc=2
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Unni
  • 61
  • 3
  • Welcome to StackOverflow. Please read [Ask questions, get answers, no distractions](https://stackoverflow.com/tour), [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers), and about [Voting](https://stackoverflow.com/help/privileges/vote-up) and [Accepting](https://stackoverflow.com/help/accepted-answer). – gremur Apr 03 '22 at 19:19

1 Answers1

-1

Possible solution is the following:

import matplotlib.pyplot as plt

sc = 1
fault = 2

plt.annotate(f'Fault location: {str(sc)}\nI_sc={str(fault)}', xy=(0.5, 0.5))
plt.show()

Returns

enter image description here

gremur
  • 1,645
  • 2
  • 7
  • 20