Home › Forums › Nazca › how to get the matplolib figure? › Reply To: how to get the matplolib figure?
28 May 2020 at 22:37
#6153
bastien
Member
Hi Ronald,
Thanks for your answer. I am aware of export_plt() and of the clear=False option and this isn’t exactly what I was looking for. Thanks for pointing at the class, I looked a bit into it and saw that you just need the coordinates of the vertices making up a cell and with help of that post I came up with something that works pretty well for what I had in mind (adding annotation to document a library of layouts or having two subplots side by side). Here is a code snippet demonstrating it in case someone’s interested:
import plotly.graph_objects as go
nd.clear_layout()
a = nd.strt(width=5, layer = 1).put()
b = nd.bend( width=5, layer = 1).put()
coord = []
for NT in nd.cell_iter(nd.cfg.defaultcell, flat=True):
if NT.cell_start:
print(f"\ncell: '{NT.cell.cell_name}'")
for i, (pgon, points, bbox) in enumerate(NT.iters['polygon']):
#print(f"{i}: points: {points}, layer: '{pgon.layer}'")
coord.append(points)
x0 = [i[0] for i in coord[0]]
x0.append(x0[0]) #to connect last point to first point in the plot
y0 = [i[1] for i in coord[0]]
y0.append(y0[0]) #to connect last point to first point in the plot
x1 = [i[0] for i in coord[1]]
x1.append(x1[0])
y1 = [i[1] for i in coord[1]]
y1.append(y1[0])
fig = go.Figure([
go.Scatter(x=x0, y=y0, fill="toself", marker=dict(opacity=0), name="arc layer1"),
go.Scatter(x=x1, y=y1, fill="toself", marker=dict(opacity=0) )
])
fig.add_annotation(
x=5,
y=2.5,
text="L",
ax=0,
ay=-40
)
fig.add_annotation(
x=0,
y=0,
text="W",
ax=-20,
ay=-40
)
fig.update_annotations(dict(
xref="x",
yref="y",
showarrow=True,
arrowhead=7
))
fig.update_layout(
yaxis = dict(
scaleanchor = "x",
scaleratio = 1,
),
showlegend = True,
width=1000,
height=1000,
autosize=False
)
fig.show()
nd.clear_layout()
Bastien