Skip to content

Commit

Permalink
examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Phlya committed May 31, 2018
1 parent 4e1e3e3 commit 42fbf6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 6 additions & 8 deletions adjustText/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def adjust_text(texts, x=None, y=None, add_objects=None, ax=None,
only_move={'points':'xy', 'text':'xy', 'objects':'xy'},
text_from_text=True, text_from_points=True,
save_steps=False, save_prefix='', save_format='png',
add_step_numbers=True, draggable=True, on_basemap=False,
add_step_numbers=True, on_basemap=False,
*args, **kwargs):
"""Iteratively adjusts the locations of texts.
Expand Down Expand Up @@ -413,13 +413,11 @@ def adjust_text(texts, x=None, y=None, add_objects=None, ax=None,
save_format (str): a format to save the steps into; default 'png
add_step_numbers (bool): whether to add step numbers as titles to the
images of saving steps
draggable (bool): whether to make the annotations draggable; default
True
on_basemap (bool): whether your plot uses the basemap library, stops
labels going over the edge of the map; default False
args and kwargs: any arguments will be fed into plt.annotate after
all the optimization is done just for plotting
args and kwargs: any arguments will be fed into ax.annotate after
all the optimization is done just for plotting the connecting arrows
if required
"""
if ax is None:
ax = plt.gca()
Expand All @@ -435,8 +433,8 @@ def adjust_text(texts, x=None, y=None, add_objects=None, ax=None,
# ydiff = np.diff(ax.get_ylim())[0]

bboxes = get_bboxes(texts, r, (1.0, 1.0), ax)
sum_width = np.sum(list(map(lambda x: x.width, bboxes)))
sum_height = np.sum(list(map(lambda x: x.height, bboxes)))
sum_width = np.sum(list(map(lambda bbox: bbox.width, bboxes)))
sum_height = np.sum(list(map(lambda bbox: bbox.height, bboxes)))
if not any(list(map(lambda val: 'x' in val, only_move.values()))):
precision_x = np.inf
else:
Expand Down
12 changes: 7 additions & 5 deletions docs/source/Examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@
" plt.xlabel('$log_2(Fold Change)$')\n",
" plt.ylabel('$-log_{10}(pvalue)$')\n",
" if adjust:\n",
" plt.title('%s iterations' % adjust_text(texts, arrowprops=dict(arrowstyle=\"-\", color='k', lw=0.5), **kwargs))\n",
" plt.title('%s iterations' % adjust_text(texts,\n",
" arrowprops=dict(arrowstyle=\"-\", color='k', lw=0.5), **kwargs))\n",
"_ = plot_volcano()"
]
},
Expand Down Expand Up @@ -490,11 +491,11 @@
" plt.xlabel('wt')\n",
" plt.ylabel('mpg')\n",
" if adjust:\n",
" plt.title('%s iterations' % adjust_text(texts, ha='center', va='center', arrowprops=dict(arrowstyle=\"-\", color='k', lw=0.5, shrinkA=0),\n",
" plt.title('%s iterations' % adjust_text(texts, arrowprops=dict(arrowstyle=\"-\", color='k', lw=0.5),\n",
" save_steps=False, save_prefix='/home/ilya/adjustText/examples/mtcars', **kwargs))\n",
" else:\n",
" plt.title('Original')\n",
"_ = plot_mtcars()"
"plot_mtcars()"
]
},
{
Expand Down Expand Up @@ -696,7 +697,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now a couple very nice real-world plots using data from universaldependencies.org v2.2 by Kim Gerdes. This is something about the prevalence of particular syntactic structures in different languages, which are colour-coded by their language group. It is really dense, in some areas, so we change some parameters to make labelling more compact than default (I would be lying if I said I knew the best values before trying a few options!). You can see how languages of some groups are very nicely clustered together!"
"Now a couple very nice real-world plots using data from universaldependencies.org v2.2 by Kim Gerdes. This is something about the prevalence of particular syntactic structures in different languages, which are colour-coded by their language group. You can see how languages of some groups are very nicely clustered together!\n",
"It is really dense in some areas, so we change some parameters to make labelling more compact than default (I would be lying if I said I knew the best values before trying a few options, although the direction of changes - lower forces and smaller `expand_` options, is quite obvious). Small forces cause it to take a while to run though."
]
},
{
Expand Down Expand Up @@ -775,7 +777,7 @@
"adjust_text(texts, col1, col2, ax=ax, precision=0.001,\n",
" expand_text=(1.01, 1.05), expand_points=(1.01, 1.05),\n",
" force_text=(0.01, 0.25), force_points=(0.01, 0.25),\n",
" arrowprops=dict(arrowstyle='-', color='0.5', alpha=.5))"
" arrowprops=dict(arrowstyle='-', color='gray', alpha=.5))"
]
},
{
Expand Down

0 comments on commit 42fbf6b

Please sign in to comment.