Ticket #8912: future_pyplot_examples.py

File future_pyplot_examples.py, 2.9 KB (added by Federico M Pouzols, 6 years ago)
Line 
1from pymantidplot.future.pyplot import *
2
3## plot arrays
4plot([0.1, 0.3, 0.2, 4])
5plot([0.1, 0.2, 0.3, 0.4], [1.2, 1.3, 0.2, 0.8])
6
7
8# Loads
9ws = Load("MAR11060.raw", OutputWorkspace="foo")
10mar = Load('MAR11060.raw', OutputWorkspace="MAR11060")
11loq=Load('LOQ48097.raw', OutputWorkspace="LOQ48097")
12ws2 = Load('HRP39182.RAW', OutputWorkspace="HRP39182")
13
14## plot workspaces
15plot(ws, 100)
16plot(ws, [100, 101, 102])
17plot('MAR11060', [10,100,500])
18plot(mar,[3, 500, 800])
19yscale('log')
20plot([mar, 'LOQ48097'], [800, 900])
21plot([mar, loq], [800, 900])
22plot(['MAR11060', loq], [800, 900])
23plot(['MAR11060', loq], [800, 900], tool='plot_spectrum')
24
25# tools
26plot_spectrum(['MAR11060', loq], [800, 900])
27plot(ws, [1, 5, 7, 100], tool='plot_bin')
28
29plot_bin(ws, [1, 5, 7, 100], linewidth=4, linestyle=':')
30xscale('log')
31
32simple_md_ws = CreateMDWorkspace(Dimensions='3',Extents='0,10,0,10,0,10',Names='x,y,z',Units='m,m,m',SplitInto='5',MaxRecursionDepth='20',OutputWorkspace=MDWWorkspaceName)
33plot(simple_md_ws, tool='plot_md')
34plot_md(simple_md_wsws)
35
36# some plot properties
37a = [0.1, 0.3, 0.2, 4]
38plot(a)
39import numpy as np
40y = np.sin(np.linspace(-2.28, 2.28, 1000))
41plot(y, linestyle='-.', marker='o', color='red')
42plot(1.5*y, '-.g', hold='on')
43plot(0.8*y, ':b', hold='on')
44plot(1.2*y, '--c', hold='on')
45xscale('log')
46yscale('log')
47
48# plot properties and return lines
49lines = plot([ws2], 0, '-r') # solid (default)
50lines = plot([ws, ws2], 0, '-.c') # dash-dotted
51lines = plot(ws, 0, '--m') # dashed
52lines = plot(ws, [0,1], ':g')  # dotted
53lines = plot(loq, [100, 104], tool='plot_spectrum', linestyle='-.', marker='*', color='red')
54lines[0].get_xdata()
55lines[0].get_ydata()
56fig = lines[0].figure()
57fig.suptitle('Example figure title')
58
59# functions
60title('Test plot of LOQ')
61xlabel('ToF')
62ylabel('Counts')
63ylim(0, 8)
64xlim(1e3, 4e4)
65xscale('log')
66grid('on')
67savefig('example_saved_figure.png')
68
69# hold
70lines = plot(loq, [100, 102], linestyle='-.', color='red')
71lines = plot(loq, 100, linestyle='-.', color='red')
72lines = plot(loq, 102, linestyle='-.', color='blue', hold='on')
73lines = plot(loq, 103, linestyle=':', color='m', hold='on')
74lines = plot(loq, 104, linestyle=':', color='k', hold='on')
75
76# multi-plot
77plot(ws, [100, 101], 'r', ws, [200, 201], 'b', tool='plot_spectrum')
78plot(ws, [100, 101], 'm', mar, [50, 41], 'b', tool='plot_spectrum')
79
80# other examples, used to fail
81ws = CreateWorkspace([1,2,3], [1.1,2.8,3.2])
82lines = plot([ws], [0], '--r', [ws], [0], 'g')
83lines = plot([ws], [0], 'r', [ws], [0], 'g')
84title('myplot_1')
85xlabel('x')
86figure(0)
87title('myplot_0')
88xlabel('x')
89print dir(lines[0])
90
91# Axes
92lines = plot(mar,[3, 500, 800])
93fig = lines[0].figure()
94all_ax = fig.axes()    # fig.axes() returns in principle a list
95ax = all_ax[0]         #  but we only use one axes
96ax.set_ylabel('--- Counts ---')
97ax.set_xlabel('--- ToF ---')
98ax.set_ylim(0, 25)
99ax.set_xlim(1e2, 4e4)
100ax.set_xscale('log')
101ax.set_yscale('log')
102ax.set_yscale('linear')
103