Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
anki-xyz committed Jun 15, 2020
1 parent 42a5dc9 commit 8f07692
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ NUtil.egg-info/SOURCES.txt
NUtil.egg-info/top_level.txt
nutil/__pycache__/__init__.cpython-36.pyc
nutil/__pycache__/image.cpython-36.pyc
nutil/__pycache__/plot.cpython-36.pyc
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,46 @@ Usage:

![Browse through random stack](browse_example.gif)

## Plot features

How to grab a figure to an RGB image numpy array:

from nutil.plot import grabFigure
from imageio import mimwrite

ims = []

for _ in range(10):
fig = plt.figure()
plt.plot(np.random.randn(100))
ims.append(grabFigure(fig))

mimwrite("random_plot.gif", ims, fps=3)

![Random plots saved as movie](random_plot.gif)

Use this function to make your paper figures nice immediately (and editable in Illustrator & Co!).
Checkout the [example file](nice_figure.svg) in SVG file format.

import seaborn as sns
from nutil.plot import paperStyle

# Font-size 8 pt by default,
# text editable
# and seaborn white style with ticks
paperStyle()

plt.figure(figsize=(3,2))
plt.plot(np.random.randn(100))
plt.xlabel("Time [au]")
plt.ylabel("Data [au]")
sns.despine(trim=True, offset=5)
plt.savefig("nice_figure.png")
plt.savefig("nice_figure.svg")


![Random plot as nice figure](nice_figure.png)

## Fake data

Moving square
Expand Down
Binary file added nice_figure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
279 changes: 279 additions & 0 deletions nice_figure.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 8 additions & 6 deletions nutil/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
import matplotlib.pyplot as plt
import seaborn as sns

def paperStyle(use_seaborn=True):
def paperStyle(font_size=8, use_seaborn=True):
"""Defines plot styles for paper
Args:
font_size (int, optional): Figure font size. Defaults to 8 (pt).
use_seaborn (bool, optional): If seaborn is used to style the plot. Defaults to True.
"""
if use_seaborn:
sns.set_style('white')
sns.set_style('ticks')

plt.rcParams['axes.labelsize'] = 8
plt.rcParams['xtick.labelsize'] = 8
plt.rcParams['ytick.labelsize'] = 8
plt.rcParams['legend.fontsize'] = 8
plt.rcParams['axes.labelsize'] = font_size
plt.rcParams['xtick.labelsize'] = font_size
plt.rcParams['ytick.labelsize'] = font_size
plt.rcParams['legend.fontsize'] = font_size
plt.rcParams['title.fontsize'] = font_size
plt.rcParams['font.family'] = ['sans-serif']
plt.rcParams['font.sans-serif'] = ['Arial']
plt.rcParams['svg.fonttype'] = 'none' # Text is not rendered
Expand All @@ -40,4 +42,4 @@ def grabFigure(fig, autoclose=True):
plt.close(fig)

# Returns numpy array
return np.frombuffer(rgb, dtype=np.uint8).reshape(shape)
return np.frombuffer(rgb, dtype=np.uint8).reshape(shape)
Binary file added random_plot.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8f07692

Please sign in to comment.