-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
….github.io Conflicts: mainsite_hidden/source/conf.py mainsite_hidden/source_plugins/conf.py
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Science Plots | ||
============= | ||
This `matplotlib <https://matplotlib.org/>`_ style `Science Plots <https://github.com/garrettj403/SciencePlots>`_ is focused to generate figures using common scientific journal styles such as IEEE. | ||
The figures are suitable to print in colored are back and white. In addition to `matplotlib <https://matplotlib.org/>`_, the style must be installed. | ||
.. code-block:: bat | ||
pip install SciencePlots | ||
""" | ||
|
||
############################################################################### | ||
# Import namespaces. | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import scienceplots | ||
|
||
############################################################################### | ||
# Generate demo x and y values. | ||
x = np.linspace(0, 10, 20) | ||
y = np.sin(x) | ||
y2 = np.cos(x) | ||
|
||
|
||
############################################################################### | ||
# Change matplotlib.pyplot style and plot data. | ||
with plt.style.context(["science", "no-latex"]): | ||
plt.figure(figsize=(6, 6)) | ||
plt.plot(x, y, marker="o", label="Line 1") | ||
plt.plot(x, y2, marker="x", label="Line 2") | ||
|
||
plt.xlabel("X") | ||
plt.ylabel("Y") | ||
plt.legend() | ||
plt.grid() | ||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Science Plots\n\nThis [matplotlib](https://matplotlib.org/) style [Science Plots](https://github.com/garrettj403/SciencePlots) is focused to generate figures using common scientific journal styles such as IEEE.\nThe figures are suitable to print in colored are back and white. In addition to [matplotlib](https://matplotlib.org/), the style must be installed.\n\n.. code-block:: bat\n\n pip install SciencePlots\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Import namespaces.\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\nimport matplotlib.pyplot as plt\nimport scienceplots" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Generate demo x and y values.\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"x = np.linspace(0, 10, 20)\ny = np.sin(x)\ny2 = np.cos(x)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Change matplotlib.pyplot style and plot data.\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"with plt.style.context([\"science\", \"no-latex\"]):\n plt.figure(figsize=(6, 6))\n plt.plot(x, y, marker=\"o\", label=\"Line 1\")\n plt.plot(x, y2, marker=\"x\", label=\"Line 2\")\n\n plt.xlabel(\"X\")\n plt.ylabel(\"Y\")\n plt.legend()\n plt.grid()\n plt.show()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# ANSI escape codes\n\nThis demo shows some possibilities of ANSI escape codes.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Change the text color\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"set the text colors to pre-defined values, followed by a reset\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"print(\"\\u001b[30m A \\u001b[31m B \\u001b[32m C \\u001b[33m D \\u001b[0mText after reset\")\nprint(\"\\u001b[34m E \\u001b[35m F \\u001b[36m G \\u001b[37m H \\u001b[0mText after reset\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"use the prefix 1 to choose are more lighter text color\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"print(\n \"\\u001b[30;1m A \\u001b[31;1m B \\u001b[32;1m C \\u001b[33;1m D \\u001b[0mText after reset\"\n)\nprint(\n \"\\u001b[34;1m E \\u001b[35;1m F \\u001b[36;1m G \\u001b[37;1m H \\u001b[0mText after reset\"\n)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"now the same with the background color\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"print(\"\\u001b[40m A \\u001b[41m B \\u001b[42m C \\u001b[43m D \\u001b[0mText after reset\")\nprint(\"\\u001b[44m E \\u001b[45m F \\u001b[46m G \\u001b[47m H \\u001b[0mText after reset\")\nprint(\n \"\\u001b[40;1m A \\u001b[41;1m B \\u001b[42;1m C \\u001b[43;1m D \\u001b[0mText after reset\"\n)\nprint(\n \"\\u001b[44;1m E \\u001b[45;1m F \\u001b[46;1m G \\u001b[47;1m H \\u001b[0mText after reset\"\n)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"use text bold, underline, italic or combine them\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"print(\n \"\\u001b[1;3;4mText bold, underline and italic \\u001b[22mRemove bold only \"\n \"\\u001b[23;1mRemove italic and set bold again \\u001b[0mReset all\"\n)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
"""1D func animation | ||
=============== | ||
This example demonstrates how matplotlib can be used to create | ||
animated movie and export these in the mp4 movie format. | ||
It is shown here with some random generated 2d images, which ware plotted via matplotlib. | ||
By using the figure handle the animation is created. So you can plot your matplot | ||
figures in your own way and used some similar syntax to create an animation. | ||
First of all you must install the matplotlib package, e.g. from | ||
https://pypi.org/project/matplotlib/ | ||
Then you must install the ffmpeg codec. A detailed description can be found on: | ||
http://blog.gregzaal.com/how-to-install-ffmpeg-on-windows/ | ||
The build version of the ffmpeg codec can be downloaded here: | ||
http://ffmpeg.zeranoe.com/builds/ | ||
Download and unzip the builds files to your harddrive. Typically the folder is like: | ||
C:\\Program files\\ffmpeg | ||
The bin folder of ffmpeg must be added to the path variables of your system: | ||
C:\\Program files\\ffmpeg\\bin | ||
Finally start the command prompt and run the command: | ||
C:\\Program files\\ffmpeg\\bin\\ffmpeg.exe -codecs | ||
or easier: | ||
ffmpeg -codecs | ||
""" | ||
|
||
import numpy as np | ||
|
||
############################################################################### | ||
# Import namespaces | ||
import matplotlib.pyplot as plt | ||
from matplotlib.animation import FuncAnimation | ||
|
||
|
||
############################################################################### | ||
# Function to generate parametric plot | ||
def parametric_plot(T, e): | ||
t = np.linspace(0, T, 1000) | ||
x = np.cos(-t) | ||
y = np.cos(-t + e) | ||
|
||
plt.plot(x, y, color="b") | ||
|
||
plt.xlim(-1.1, 1.1) | ||
plt.ylim(-1.1, 1.1) | ||
plt.gca().set_aspect("equal", adjustable="box") | ||
plt.title(f"T = {T:.2f}, e = {e:.2f}") | ||
|
||
|
||
############################################################################### | ||
# Function to calculate ellipse parameters | ||
def calculate_ellipse_params(T, e): | ||
t = np.linspace(0, T, 1000) | ||
x = np.cos(-t) | ||
y = np.cos(-t + e) | ||
|
||
# Calculate width and height | ||
width = np.max(x) - np.min(x) | ||
height = np.max(y) - np.min(y) | ||
|
||
# Calculate covariance matrix | ||
covariance_matrix = np.cov(x, y) | ||
|
||
# Calculate eigenvalues and eigenvectors | ||
eigenvalues, eigenvectors = np.linalg.eig(covariance_matrix) | ||
|
||
# Get angle of rotation (angle of major axis with respect to x-axis) | ||
major_axis_index = np.argmax(eigenvalues) | ||
major_axis_vector = eigenvectors[:, major_axis_index] | ||
angle_rad = np.arctan2(major_axis_vector[1], major_axis_vector[0]) | ||
angle_deg = np.degrees(angle_rad) | ||
|
||
return width, height, angle_deg | ||
|
||
|
||
############################################################################### | ||
# Calculate ellipse parameters for a full oscillation | ||
T_full = 2 * np.pi | ||
e_full = 45 | ||
width, height, angle_deg = calculate_ellipse_params(T_full, e_full) | ||
|
||
# Create figure and plot ellipse | ||
fig, ax = plt.subplots() | ||
|
||
|
||
# Setting up the animation | ||
def update(frame): | ||
ax.clear() | ||
parametric_plot(frame, e) | ||
|
||
|
||
e = 45 | ||
ani = FuncAnimation( | ||
fig, update, frames=np.linspace(0.01, T_full, 100), repeat=True, interval=50 | ||
) | ||
|
||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Sankey diagram\n\nThis demo shows how to use the Python ``plotly`` package under itom.\n\nIn order to show plotly outputs in itom figures, it is only necessary\nto import the ``itomPlotlyRenderer`` module once at the beginning of your\nscript. This adds an itom specific renderer to Plotly and uses it as default.\n\nThe plotly outputs are then shown in an itom designerPlugin with the name\n``plotlyPlot``.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import itomPlotlyRenderer\n\n\nimport plotly.graph_objects as go\nimport json\n\nwith open(\"sankey_energy.json\") as file:\n data = json.load(file)\n\n# override gray link colors with 'source' colors\nopacity = 0.4\n# change 'magenta' to its 'rgba' value to add opacity\ndata[\"data\"][0][\"node\"][\"color\"] = [\n \"rgba(255,0,255, 0.8)\" if color == \"magenta\" else color\n for color in data[\"data\"][0][\"node\"][\"color\"]\n]\ndata[\"data\"][0][\"link\"][\"color\"] = [\n data[\"data\"][0][\"node\"][\"color\"][src].replace(\"0.8\", str(opacity))\n for src in data[\"data\"][0][\"link\"][\"source\"]\n]\n\nfig = go.Figure(\n data=[\n go.Sankey(\n valueformat=\".0f\",\n valuesuffix=\"TWh\",\n # Define nodes\n node=dict(\n pad=15,\n thickness=15,\n line=dict(color=\"black\", width=0.5),\n label=data[\"data\"][0][\"node\"][\"label\"],\n color=data[\"data\"][0][\"node\"][\"color\"],\n ),\n # Add links\n link=dict(\n source=data[\"data\"][0][\"link\"][\"source\"],\n target=data[\"data\"][0][\"link\"][\"target\"],\n value=data[\"data\"][0][\"link\"][\"value\"],\n label=data[\"data\"][0][\"link\"][\"label\"],\n color=data[\"data\"][0][\"link\"][\"color\"],\n ),\n )\n ]\n)\n\nfig.update_layout(\n title_text=\"Energy forecast for 2050<br>Source: Department of Energy & Climate Change, \"\n \"Tom Counsell via <a href='https://bost.ocks.org/mike/sankey/'>Mike Bostock</a>\",\n font_size=10,\n)\nfig.show()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |