Last active
January 31, 2019 09:50
-
-
Save dtasev/e719e582383d36d3fe877287536a1807 to your computer and use it in GitHub Desktop.
Mantid Scripts
This file contains hidden or 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
# The following line helps with future compatibility with Python 3 | |
# print must now be used as a function, e.g print('Hello','World') | |
from __future__ import (absolute_import, division, print_function, unicode_literals) | |
# import mantid algorithms, numpy and matplotlib | |
from mantid.simpleapi import * | |
import matplotlib.pyplot as plt | |
import numpy as np | |
from mantid.kernel import V3D | |
# Create PositionTable | |
tableWS = CreateEmptyTableWorkspace() | |
# Add some columns, Recognized types are: int,float,double,bool,str,V3D,long64 | |
tableWS.addColumn(type="int",name="ID") | |
tableWS.addColumn(type="str",name="Name") | |
tableWS.addColumn(type="int",name="Position_1") | |
tableWS.addColumn(type="float",name="Value_1") | |
tableWS.addColumn(type="float",name="Error_1") | |
tableWS.addColumn(type="int",name="Position_2") | |
tableWS.addColumn(type="float",name="Value_2") | |
tableWS.addColumn(type="float",name="Error_2") | |
tableWS.addColumn(type="int",name="Position_3") | |
tableWS.addColumn(type="float",name="Value_3") | |
tableWS.addColumn(type="float",name="Error_3") | |
# Populate the columns for three detectors | |
for j in range(100): | |
nextRow = { 'ID': j, | |
'Name': "Entry {0}".format(j), | |
'Position_1': j, | |
'Value_1': j/0.00444, | |
'Error_1': j/0.125, | |
'Position_2': j, | |
'Value_2': j/0.00888, | |
'Error_2': j/0.250, | |
'Position_3': j, | |
'Value_3': j/0.016, | |
'Error_3': j/0.500, | |
} | |
tableWS.addRow ( nextRow ) |
This file contains hidden or 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
import matplotlib | |
import matplotlib.pyplot as plt | |
import numpy as np | |
def do_plot(): | |
fig, ax0 = plt.subplots() | |
# make these smaller to increase the resolution | |
dx, dy = 0.01, 0.01 | |
# generate 2 2d grids for the x & y bounds | |
y, x = np.mgrid[slice(1, 30 + dy, dy), | |
slice(1, 30 + dx, dx)] | |
z = np.sin(x)**10 + np.cos(10 + y*x) * np.cos(x) | |
# x and y are bounds, so z should be the value *inside* those bounds. | |
# Therefore, remove the last value from the z array. | |
z = z[:-1, :-1] | |
cmap = plt.get_cmap('viridis') | |
im = ax0.pcolormesh(x, y, z, cmap=cmap) | |
return fig | |
for i in range(2): | |
fig = do_plot() | |
plt.show() | |
all_objs = gc.get_objects() | |
print("Num of all objects", len(all_objs)) | |
plots = [x for x in all_objs if "fig" in str(type(x)).lower()] | |
print("Plots:", len(plots)) | |
print(all_objs[1414]) |
This file contains hidden or 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
from qtpy.QtWidgets import QApplication | |
a = QApplication.topLevelWidgets() | |
all = [x for x in a if "plot" in str(type(x))] | |
t = all[0] | |
print("Num widgets of type {}".format(len(all))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment