-
Notifications
You must be signed in to change notification settings - Fork 2
/
visualization.py
122 lines (101 loc) · 3.21 KB
/
visualization.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
'''
photometry.py. Visualize the photometric output of a Wavefront obj. model.
Copyright (C) 2020 Drew Allen McNeely
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
'''
import plotly.offline as po
import plotly.express as px
import plotly.graph_objs as go
import numpy as np
from geometry import IcoSphere, Rotation
import pandas as pd
import progressbar as pb
R = Rotation.for_icosphere()
sphere = IcoSphere.icosahedron().divided(4)
def plot_function_triangles(f, filename):
#for t in range(5,10):
#sphere = IcoSphere.icosahedron().divided().reduced(t)
geo = sphere.geojson
vals = sphere.mapf(f)
ids = range(len(vals))
dat = {'ids':ids, 'vals':vals}
df = pd.DataFrame(data=dat)
fig = px.choropleth(df,
geojson=geo,
locations='ids',
color='vals',
color_continuous_scale="Viridis",
)
fig.data[0].marker.line.width = 0
configure_fig(fig)
po.plot(fig, filename=filename)
def plot_function_points(f):
lats = sphere.bary_lats
lons = sphere.bary_lons
print("hello")
vals = sphere.mapf(f)
fig = px.scatter_geo(lat=lats, lon=lons, color=vals,)
configure_fig(fig)
po.plot(fig, filename="points.html")
def plot_sphere_points():
fig = px.scatter_geo(lat=lats, lon=lons)
po.plot(fig, filename="points.html")
def configure_fig(fig):
fig.update_geos(
visible=False,
projection=dict(
type="mollweide",
rotation=dict(
lon=.5,
lat=.5,
roll=0)),
lataxis_showgrid=True,
lonaxis_showgrid=True,
)
projections = [
"mollweide",
"orthographic",
"stereographic",
"equirectangular",
"mercator",
"azimuthal equal area",
"azimuthal equidistant",
"conic equal area",
"conic conformal",
"conic equidistant",
"gnomonic",
]
buttons = [ dict( args=['geo.projection.type', p], label=p, method='relayout' ) for p in projections ]
annot = list([ dict(
x=0.1,
y=0.8,
text='Projection',
yanchor='bottom',
xref='paper',
xanchor='right',
showarrow=False
)])
fig.update_layout(
updatemenus=list([ dict(
x=0.1,
y=0.8,
buttons=buttons,
yanchor='top',
)]),
annotations=annot,
)
return fig
if __name__ == "__main__":
"""Test this module on a simple function."""
def f(p): return p.x
plot_function_triangles(f)