-
Notifications
You must be signed in to change notification settings - Fork 248
WIP: DOC: Add a gallery example to show formating long text as paragraphs #4592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
85e411c
9839b8b
a9efead
8f7d1f5
d44dd9e
e0081b0
e71117c
ecc9232
ecdba41
9e17927
025baeb
6f73c9c
fd044df
19eb614
c8ee6f2
4280487
06e8147
8a01b35
df8ecd1
2b62f3e
c999cbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| """ | ||
| Paragraphs of long text | ||
| ======================= | ||
|
|
||
| To typeset long text as one or several paragraphs the :meth:`pygmt.Figure.paragraph` | ||
| method can be used. The ``parwidth`` and ``linespacing`` parameters allow to set | ||
| the width of the paragraph and line spacing, respectively. The desired text can | ||
| be provided using two ways to indicate a new paragraph: | ||
|
|
||
| (1) a single string separated by a blank line | ||
| (2) a list of strings, whereby each string needs to end with a white space | ||
|
|
||
| During plotting the paragraphs are automatically separated by a blank line. | ||
|
|
||
| For details on text formatting see the gallery example | ||
| :doc:`Text formatting </gallery/embellishments/text_formatting>`. | ||
| """ | ||
|
|
||
| # %% | ||
| import pygmt | ||
|
|
||
| text = [ | ||
| "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ", | ||
| "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", | ||
| ] | ||
|
|
||
| fig = pygmt.Figure() | ||
| fig.basemap(region=[-5, 5, -5, 5], projection="X10c/10c", frame=True) | ||
|
|
||
| fig.paragraph( | ||
| text=text, | ||
| x=0, | ||
| y=0, | ||
| parwidth="4.5c", | ||
| linespacing="12p", | ||
| alignment="center", | ||
| justify="MC", | ||
| angle=45, | ||
| font="10p,Helvetica-Bold,steelblue", | ||
| fill="lightgray", # font color ignored | ||
| pen="1p,gray10", # font color ignored | ||
| ) | ||
|
|
||
| fig.show() | ||
|
|
||
|
|
||
| # %% | ||
| text = [ | ||
| "@_It was the best of times, it was the worst of times@_, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way -- ", | ||
| "in short, the period was so far like the present period, that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only", | ||
| ] | ||
|
|
||
| fig = pygmt.Figure() | ||
| fig.basemap(region=[-5, 5, -5, 5], projection="X15c/15c", frame=True) | ||
|
|
||
| fig.paragraph( | ||
| text=text, | ||
| x=0, | ||
| y=0, | ||
| parwidth="12c", | ||
| linespacing="18p", | ||
| alignment="center", | ||
| justify="MC", | ||
| font="16p,Times-Roman,red", # should now work with fill | ||
| fill="lightblue", | ||
| pen="2p", | ||
| # S="8p/-8p/darkblue", # not supported yet | ||
| # C="8p+tc", # not supported yet | ||
|
Comment on lines
+67
to
+68
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before continuing with this example in PyGMT we need to introduce the parameters for -S and -C.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't have to reproduce the example exactly, so -S and -C are not needed.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, we can still extend the gallery example later to include this parameters if we feel this makes sense. |
||
| ) | ||
|
|
||
| fig.show() | ||
|
|
||
|
|
||
| # %% | ||
| # taken from pygmt/tests/test_paragraph.py | ||
| text = [ | ||
| " Paragraph 1: Two leading whitespaces. Three inline whitespaces. Two trailing whitespaces. ", | ||
| " Paragraph 2: One leading tab results in one indentation (four whitespaces by default).", | ||
| " Paragraph 3: Two leading tabs results in two indentation (eight whitespaces by default).", | ||
| "Paragraph 4: Multiple inline tabs are converted to multiple spaces. Trailing tabs have not effects. ", | ||
| "Paragraph 5: Mixing tabs and spaces. 2T3STST( ).", | ||
| "\nParagraph 6: Leading newline is converted to a space. Trailing newlines are converted to spaces.\n\n", | ||
| "\n\nParagraph 7: Multiple leading newline are converted to multiple spaces. xxx yyy zzz.", | ||
| "Paragraph 8: Newlines insiden a paragraph\nare converted to spaces.", | ||
| "Paragraph 9: This is the last paragraph.", | ||
| ] | ||
|
|
||
| fig = pygmt.Figure() | ||
| fig.basemap(region=[-5, 5, -5, 5], projection="X15c/15c", frame=True) | ||
|
|
||
| fig.paragraph( | ||
| text=text, | ||
| x=0, | ||
| y=0, | ||
| parwidth="12c", | ||
| linespacing="18p", | ||
| ) | ||
|
|
||
| fig.show() | ||
Uh oh!
There was an error while loading. Please reload this page.