-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kenneth Hart
committed
Sep 5, 2019
1 parent
12d7022
commit 8af381b
Showing
10 changed files
with
175 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
auto_examples/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Gallery of Examples | ||
=================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Command Line Introduction | ||
------------------------- | ||
|
||
These examples introduce the options available in XML input files, excuted | ||
from the command line. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -*- coding: utf-8 -*- | ||
r""" | ||
1. Basic Example | ||
++++++++++++++++ | ||
This input files contains two phases with a few options. | ||
XML Input File | ||
^^^^^^^^^^^^^^ | ||
The basename for this file is ``intro_1_basic.xml``. | ||
The file can be run using this command:: | ||
microstructpy --demo=intro_1_basic.xml | ||
File contents: | ||
.. literalinclude:: ../../../../examples/intro_1_basic.xml | ||
:language: xml | ||
Explanation | ||
^^^^^^^^^^^ | ||
There are two materials, in a 2:1 ratio based on volume. | ||
The first is a matrix, which is represented with small circles. | ||
The second material consists of circular inclusions with diameter 2. | ||
These two materials fill a square domain. | ||
The bottom-left corner of the rectangle is the origin, which puts the | ||
rectangle in the first quadrant. | ||
The side length is 20, which is 10x the size of the inclusions. | ||
PNG files of each step in the process will be output, as well as the | ||
intermediate text files. | ||
They are saved in a folder named ``intro_1_basic``, in the current directory | ||
(i.e ``./intro_1_basic``). | ||
Output Plots | ||
^^^^^^^^^^^^ | ||
""" | ||
|
||
# sphinx_gallery_thumbnail_number = 3 | ||
|
||
import os | ||
import shutil | ||
|
||
import matplotlib.pyplot as plt | ||
import pylab | ||
|
||
import microstructpy as msp | ||
|
||
filename = '../../examples/intro_1_basic.xml' | ||
|
||
in_data = msp.cli.read_input(filename) | ||
phases = in_data['material'] | ||
domain = in_data['domain'] | ||
kwargs = in_data['settings'] | ||
kwargs['verbose'] = False | ||
msp.cli.run(phases, domain, **kwargs) | ||
|
||
dpi = 300 | ||
|
||
for plot_name in ['seeds', 'polymesh', 'trimesh']: | ||
src = os.path.join('../../examples/intro_1_basic', plot_name + '.png') | ||
im = plt.imread(src) | ||
|
||
figsize = (im.shape[0] / dpi, im.shape[1] / dpi) | ||
|
||
fig = plt.figure(figsize=figsize, dpi=dpi) | ||
ax = fig.add_axes([0, 0, 1, 1]) | ||
ax.set_axis_off() | ||
ax.get_xaxis().set_visible(False) | ||
ax.get_yaxis().set_visible(False) | ||
plt.imshow(im) | ||
plt.axis('tight') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
r""" | ||
Colormaps alter your perception | ||
=============================== | ||
Here I plot the function | ||
.. math:: f(x, y) = \sin(x) + \cos(y) | ||
with different colormaps. | ||
""" | ||
|
||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
x = np.linspace(-np.pi, np.pi, 300) | ||
xx, yy = np.meshgrid(x, x) | ||
z = np.cos(xx) + np.cos(yy) | ||
|
||
plt.figure() | ||
plt.imshow(z) | ||
|
||
plt.figure() | ||
plt.imshow(z, cmap=plt.cm.get_cmap('hot')) | ||
|
||
plt.figure() | ||
plt.imshow(z, cmap=plt.cm.get_cmap('Spectral'), | ||
interpolation='none') | ||
|
||
# Not needed for the Gallery. | ||
# Only for direct execution | ||
plt.show() | ||
|
||
################################################ | ||
# You can define blocks in your source code | ||
# with interleaving prose. | ||
# | ||
|
||
print("This writes to stdout and will be", | ||
" displayed in the HTML file") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Plotting the exponential function | ||
================================= | ||
A simple example for ploting two figures of a exponential | ||
function in order to test the autonomy of the gallery | ||
stacking multiple images. | ||
""" | ||
|
||
# Code source: Óscar Nájera | ||
# License: BSD 3 clause | ||
|
||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
def main(): | ||
N = 100 | ||
x = np.linspace(-1, 2, N) | ||
y = np.exp(x) | ||
|
||
plt.figure() | ||
plt.plot(x, y) | ||
plt.xlabel('$x$') | ||
plt.ylabel('$\exp(x)$') | ||
|
||
plt.figure() | ||
plt.plot(x, -np.exp(-x)) | ||
plt.xlabel('$x$') | ||
plt.ylabel('$-\exp(-x)$') | ||
|
||
plt.show() | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters