Skip to content

Commit 8d98463

Browse files
committed
better warning message formatting
1 parent ecfd7a6 commit 8d98463

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

plotly/matplotlylib/renderer.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# Warning format
1515
def warning_on_one_line(message, category, filename, lineno, file=None, line=None):
16-
return ' %s:%s: %s:\n%s\n' % (filename, lineno, category.__name__, message)
16+
return '%s:%s: %s:\n\n%s\n\n' % (filename, lineno, category.__name__, message)
1717
warnings.formatwarning = warning_on_one_line
1818

1919
class PlotlyRenderer(Renderer):
@@ -503,14 +503,13 @@ def draw_text(self, **props):
503503
"""
504504
self.msg += " Attempting to draw an mpl text object\n"
505505
if not mpltools.check_corners(props['mplobj'], self.mpl_fig):
506-
warnings.warn("Looks like the annotation(s) you are trying "
507-
"to draw lies/lay outside the given figure size.\n"
508-
"Therefore, the resulting Plotly figure may not be "
509-
"large enough to view the full text.\n"
510-
"To adjust the size of the figure, use the "
511-
"'width' and 'height' keys in the Layout object. "
512-
"Alternatively, use the Margin object to adjust the "
513-
"figure's margins.")
506+
warnings.warn("Looks like the annotation(s) you are trying \n"
507+
"to draw lies/lay outside the given figure size.\n\n"
508+
"Therefore, the resulting Plotly figure may not be \n"
509+
"large enough to view the full text. To adjust \n"
510+
"the size of the figure, use the 'width' and \n"
511+
"'height' keys in the Layout object. Alternatively,\n"
512+
"use the Margin object to adjust the figure's margins.")
514513
align = props['mplobj']._multialignment
515514
if not align:
516515
align = props['style']['halign'] # mpl default

plotly/tools.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# Warning format
1818
def warning_on_one_line(message, category, filename, lineno, file=None, line=None):
19-
return ' %s:%s: %s:\n%s\n' % (filename, lineno, category.__name__, message)
19+
return '%s:%s: %s:\n\n%s\n\n' % (filename, lineno, category.__name__, message)
2020
warnings.formatwarning = warning_on_one_line
2121

2222
try:
@@ -531,12 +531,12 @@ def _replace_newline(obj):
531531
elif isinstance(obj, (str, unicode)):
532532
s = obj.replace('\n', '<br>')
533533
if s != obj:
534-
warnings.warn("Looks like you used a newline character: '\\n'.\n"
535-
"Plotly uses a subset of HTML escape characters "
536-
"to do things like newline, bold, italics, etc.\n"
537-
"Your newline characters have been converted to "
538-
"'<br>' so they will show up right on your Plotly "
539-
"figure!")
534+
warnings.warn("Looks like you used a newline character: '\\n'.\n\n"
535+
"Plotly uses a subset of HTML escape characters\n"
536+
"to do things like newline (<br>), bold (<b></b>),\n"
537+
"italics (<i></i>), etc. Your newline characters \n"
538+
"have been converted to '<br>' so they will show \n"
539+
"up right on your Plotly figure!")
540540
return s
541541
else:
542542
return obj # we return the actual reference... but DON'T mutate.

0 commit comments

Comments
 (0)