Skip to content

Commit 01fda4a

Browse files
committed
remove JHEPC banner
1 parent 6127608 commit 01fda4a

File tree

7,079 files changed

+108612
-41879
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

7,079 files changed

+108612
-41879
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": false
8+
},
9+
"outputs": [],
10+
"source": [
11+
"%matplotlib inline"
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"metadata": {},
17+
"source": [
18+
"\n# Demo Axis Direction\n\n\n\n"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {
25+
"collapsed": false
26+
},
27+
"outputs": [],
28+
"source": [
29+
"import numpy as np\nimport matplotlib.pyplot as plt\nimport mpl_toolkits.axisartist.angle_helper as angle_helper\nimport mpl_toolkits.axisartist.grid_finder as grid_finder\nfrom matplotlib.projections import PolarAxes\nfrom matplotlib.transforms import Affine2D\n\nimport mpl_toolkits.axisartist as axisartist\n\nfrom mpl_toolkits.axisartist.grid_helper_curvelinear import \\\n GridHelperCurveLinear\n\n\ndef setup_axes(fig, rect):\n \"\"\"\n polar projection, but in a rectangular box.\n \"\"\"\n\n # see demo_curvelinear_grid.py for details\n tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform()\n\n extreme_finder = angle_helper.ExtremeFinderCycle(20, 20,\n lon_cycle=360,\n lat_cycle=None,\n lon_minmax=None,\n lat_minmax=(0, np.inf),\n )\n\n grid_locator1 = angle_helper.LocatorDMS(12)\n grid_locator2 = grid_finder.MaxNLocator(5)\n\n tick_formatter1 = angle_helper.FormatterDMS()\n\n grid_helper = GridHelperCurveLinear(tr,\n extreme_finder=extreme_finder,\n grid_locator1=grid_locator1,\n grid_locator2=grid_locator2,\n tick_formatter1=tick_formatter1\n )\n\n ax1 = axisartist.Subplot(fig, rect, grid_helper=grid_helper)\n ax1.axis[:].toggle(ticklabels=False)\n\n fig.add_subplot(ax1)\n\n ax1.set_aspect(1.)\n ax1.set_xlim(-5, 12)\n ax1.set_ylim(-5, 10)\n\n return ax1\n\n\ndef add_floating_axis1(ax1):\n ax1.axis[\"lat\"] = axis = ax1.new_floating_axis(0, 30)\n axis.label.set_text(r\"$\\theta = 30^{\\circ}$\")\n axis.label.set_visible(True)\n\n return axis\n\n\ndef add_floating_axis2(ax1):\n ax1.axis[\"lon\"] = axis = ax1.new_floating_axis(1, 6)\n axis.label.set_text(r\"$r = 6$\")\n axis.label.set_visible(True)\n\n return axis\n\n\nfig = plt.figure(figsize=(8, 4))\nfig.subplots_adjust(left=0.01, right=0.99, bottom=0.01, top=0.99,\n wspace=0.01, hspace=0.01)\n\nfor i, d in enumerate([\"bottom\", \"left\", \"top\", \"right\"]):\n ax1 = setup_axes(fig, rect=241++i)\n axis = add_floating_axis1(ax1)\n axis.set_axis_direction(d)\n ax1.annotate(d, (0, 1), (5, -5),\n xycoords=\"axes fraction\", textcoords=\"offset points\",\n va=\"top\", ha=\"left\")\n\nfor i, d in enumerate([\"bottom\", \"left\", \"top\", \"right\"]):\n ax1 = setup_axes(fig, rect=245++i)\n axis = add_floating_axis2(ax1)\n axis.set_axis_direction(d)\n ax1.annotate(d, (0, 1), (5, -5),\n xycoords=\"axes fraction\", textcoords=\"offset points\",\n va=\"top\", ha=\"left\")\n\nplt.show()"
30+
]
31+
}
32+
],
33+
"metadata": {
34+
"kernelspec": {
35+
"display_name": "Python 3",
36+
"language": "python",
37+
"name": "python3"
38+
},
39+
"language_info": {
40+
"codemirror_mode": {
41+
"name": "ipython",
42+
"version": 3
43+
},
44+
"file_extension": ".py",
45+
"mimetype": "text/x-python",
46+
"name": "python",
47+
"nbconvert_exporter": "python",
48+
"pygments_lexer": "ipython3",
49+
"version": "3.6.8"
50+
}
51+
},
52+
"nbformat": 4,
53+
"nbformat_minor": 0
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": false
8+
},
9+
"outputs": [],
10+
"source": [
11+
"%matplotlib inline"
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"metadata": {},
17+
"source": [
18+
"\n# SVG Tooltip\n\n\nThis example shows how to create a tooltip that will show up when\nhovering over a matplotlib patch.\n\nAlthough it is possible to create the tooltip from CSS or javascript,\nhere we create it in matplotlib and simply toggle its visibility on\nwhen hovering over the patch. This approach provides total control over\nthe tooltip placement and appearance, at the expense of more code up\nfront.\n\nThe alternative approach would be to put the tooltip content in `title`\nattributes of SVG objects. Then, using an existing js/CSS library, it\nwould be relatively straightforward to create the tooltip in the\nbrowser. The content would be dictated by the `title` attribute, and\nthe appearance by the CSS.\n\n\n:author: David Huard\n\n"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {
25+
"collapsed": false
26+
},
27+
"outputs": [],
28+
"source": [
29+
"import matplotlib.pyplot as plt\nimport xml.etree.ElementTree as ET\nfrom io import BytesIO\n\nET.register_namespace(\"\", \"http://www.w3.org/2000/svg\")\n\nfig, ax = plt.subplots()\n\n# Create patches to which tooltips will be assigned.\nrect1 = plt.Rectangle((10, -20), 10, 5, fc='blue')\nrect2 = plt.Rectangle((-20, 15), 10, 5, fc='green')\n\nshapes = [rect1, rect2]\nlabels = ['This is a blue rectangle.', 'This is a green rectangle']\n\nfor i, (item, label) in enumerate(zip(shapes, labels)):\n patch = ax.add_patch(item)\n annotate = ax.annotate(labels[i], xy=item.get_xy(), xytext=(0, 0),\n textcoords='offset points', color='w', ha='center',\n fontsize=8, bbox=dict(boxstyle='round, pad=.5',\n fc=(.1, .1, .1, .92),\n ec=(1., 1., 1.), lw=1,\n zorder=1))\n\n ax.add_patch(patch)\n patch.set_gid('mypatch_{:03d}'.format(i))\n annotate.set_gid('mytooltip_{:03d}'.format(i))\n\n# Save the figure in a fake file object\nax.set_xlim(-30, 30)\nax.set_ylim(-30, 30)\nax.set_aspect('equal')\n\nf = BytesIO()\nplt.savefig(f, format=\"svg\")\n\n# --- Add interactivity ---\n\n# Create XML tree from the SVG file.\ntree, xmlid = ET.XMLID(f.getvalue())\ntree.set('onload', 'init(evt)')\n\nfor i in shapes:\n # Get the index of the shape\n index = shapes.index(i)\n # Hide the tooltips\n tooltip = xmlid['mytooltip_{:03d}'.format(index)]\n tooltip.set('visibility', 'hidden')\n # Assign onmouseover and onmouseout callbacks to patches.\n mypatch = xmlid['mypatch_{:03d}'.format(index)]\n mypatch.set('onmouseover', \"ShowTooltip(this)\")\n mypatch.set('onmouseout', \"HideTooltip(this)\")\n\n# This is the script defining the ShowTooltip and HideTooltip functions.\nscript = \"\"\"\n <script type=\"text/ecmascript\">\n <![CDATA[\n\n function init(evt) {\n if ( window.svgDocument == null ) {\n svgDocument = evt.target.ownerDocument;\n }\n }\n\n function ShowTooltip(obj) {\n var cur = obj.id.split(\"_\")[1];\n var tip = svgDocument.getElementById('mytooltip_' + cur);\n tip.setAttribute('visibility',\"visible\")\n }\n\n function HideTooltip(obj) {\n var cur = obj.id.split(\"_\")[1];\n var tip = svgDocument.getElementById('mytooltip_' + cur);\n tip.setAttribute('visibility',\"hidden\")\n }\n\n ]]>\n </script>\n \"\"\"\n\n# Insert the script at the top of the file and save it.\ntree.insert(0, ET.XML(script))\nET.ElementTree(tree).write('svg_tooltip.svg')"
30+
]
31+
}
32+
],
33+
"metadata": {
34+
"kernelspec": {
35+
"display_name": "Python 3",
36+
"language": "python",
37+
"name": "python3"
38+
},
39+
"language_info": {
40+
"codemirror_mode": {
41+
"name": "ipython",
42+
"version": 3
43+
},
44+
"file_extension": ".py",
45+
"mimetype": "text/x-python",
46+
"name": "python",
47+
"nbconvert_exporter": "python",
48+
"pygments_lexer": "ipython3",
49+
"version": "3.6.8"
50+
}
51+
},
52+
"nbformat": 4,
53+
"nbformat_minor": 0
54+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'''
2+
===========
3+
Masked Demo
4+
===========
5+
6+
Plot lines with points masked out.
7+
8+
This would typically be used with gappy data, to
9+
break the line at the data gaps.
10+
'''
11+
12+
import matplotlib.pyplot as plt
13+
import numpy as np
14+
15+
x = np.arange(0, 2*np.pi, 0.02)
16+
y = np.sin(x)
17+
y1 = np.sin(2*x)
18+
y2 = np.sin(3*x)
19+
ym1 = np.ma.masked_where(y1 > 0.5, y1)
20+
ym2 = np.ma.masked_where(y2 < -0.5, y2)
21+
22+
lines = plt.plot(x, y, x, ym1, x, ym2, 'o')
23+
plt.setp(lines[0], linewidth=4)
24+
plt.setp(lines[1], linewidth=2)
25+
plt.setp(lines[2], markersize=10)
26+
27+
plt.legend(('No mask', 'Masked if > 0.5', 'Masked if < -0.5'),
28+
loc='upper right')
29+
plt.title('Masked line demo')
30+
plt.show()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
=============
3+
Keypress Demo
4+
=============
5+
6+
Show how to connect to keypress events
7+
"""
8+
import sys
9+
import numpy as np
10+
import matplotlib.pyplot as plt
11+
12+
13+
def press(event):
14+
print('press', event.key)
15+
sys.stdout.flush()
16+
if event.key == 'x':
17+
visible = xl.get_visible()
18+
xl.set_visible(not visible)
19+
fig.canvas.draw()
20+
21+
# Fixing random state for reproducibility
22+
np.random.seed(19680801)
23+
24+
25+
fig, ax = plt.subplots()
26+
27+
fig.canvas.mpl_connect('key_press_event', press)
28+
29+
ax.plot(np.random.rand(12), np.random.rand(12), 'go')
30+
xl = ax.set_xlabel('easy come, easy go')
31+
ax.set_title('Press a key')
32+
plt.show()
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
==============
3+
Legend Picking
4+
==============
5+
6+
Enable picking on the legend to toggle the original line on and off
7+
"""
8+
import numpy as np
9+
import matplotlib.pyplot as plt
10+
11+
t = np.arange(0.0, 0.2, 0.1)
12+
y1 = 2*np.sin(2*np.pi*t)
13+
y2 = 4*np.sin(2*np.pi*2*t)
14+
15+
fig, ax = plt.subplots()
16+
ax.set_title('Click on legend line to toggle line on/off')
17+
line1, = ax.plot(t, y1, lw=2, label='1 HZ')
18+
line2, = ax.plot(t, y2, lw=2, label='2 HZ')
19+
leg = ax.legend(loc='upper left', fancybox=True, shadow=True)
20+
leg.get_frame().set_alpha(0.4)
21+
22+
23+
# we will set up a dict mapping legend line to orig line, and enable
24+
# picking on the legend line
25+
lines = [line1, line2]
26+
lined = dict()
27+
for legline, origline in zip(leg.get_lines(), lines):
28+
legline.set_picker(5) # 5 pts tolerance
29+
lined[legline] = origline
30+
31+
32+
def onpick(event):
33+
# on the pick event, find the orig line corresponding to the
34+
# legend proxy line, and toggle the visibility
35+
legline = event.artist
36+
origline = lined[legline]
37+
vis = not origline.get_visible()
38+
origline.set_visible(vis)
39+
# Change the alpha on the line in the legend so we can see what lines
40+
# have been toggled
41+
if vis:
42+
legline.set_alpha(1.0)
43+
else:
44+
legline.set_alpha(0.2)
45+
fig.canvas.draw()
46+
47+
fig.canvas.mpl_connect('pick_event', onpick)
48+
49+
plt.show()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Placing text boxes
3+
==================
4+
5+
When decorating axes with text boxes, two useful tricks are to place
6+
the text in axes coordinates (see :doc:`/tutorials/advanced/transforms_tutorial`), so the
7+
text doesn't move around with changes in x or y limits. You can also
8+
use the ``bbox`` property of text to surround the text with a
9+
:class:`~matplotlib.patches.Patch` instance -- the ``bbox`` keyword
10+
argument takes a dictionary with keys that are Patch properties.
11+
"""
12+
13+
import numpy as np
14+
import matplotlib.pyplot as plt
15+
16+
np.random.seed(19680801)
17+
18+
fig, ax = plt.subplots()
19+
x = 30*np.random.randn(10000)
20+
mu = x.mean()
21+
median = np.median(x)
22+
sigma = x.std()
23+
textstr = '\n'.join((
24+
r'$\mu=%.2f$' % (mu, ),
25+
r'$\mathrm{median}=%.2f$' % (median, ),
26+
r'$\sigma=%.2f$' % (sigma, )))
27+
28+
ax.hist(x, 50)
29+
# these are matplotlib.patch.Patch properties
30+
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
31+
32+
# place a text box in upper left in axes coords
33+
ax.text(0.05, 0.95, textstr, transform=ax.transAxes, fontsize=14,
34+
verticalalignment='top', bbox=props)
35+
36+
plt.show()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
============
3+
Scatter plot
4+
============
5+
6+
This example showcases a simple scatter plot.
7+
"""
8+
import numpy as np
9+
import matplotlib.pyplot as plt
10+
11+
# Fixing random state for reproducibility
12+
np.random.seed(19680801)
13+
14+
15+
N = 50
16+
x = np.random.rand(N)
17+
y = np.random.rand(N)
18+
colors = np.random.rand(N)
19+
area = (30 * np.random.rand(N))**2 # 0 to 15 point radii
20+
21+
plt.scatter(x, y, s=area, c=colors, alpha=0.5)
22+
plt.show()
23+
24+
#############################################################################
25+
#
26+
# ------------
27+
#
28+
# References
29+
# """"""""""
30+
#
31+
# The use of the following functions and methods is shown in this example:
32+
import matplotlib
33+
34+
matplotlib.axes.Axes.scatter
35+
matplotlib.pyplot.scatter

0 commit comments

Comments
 (0)