Iโve been given a DXF file at work to analyse it, and they want me to plot it as well. This file contains a layout of a private area. The data looks like this:
Layer PaperSpace SubClasses Linetype EntityHandle Text geometry
860 0 None AcDbEntity:AcDbPolyline None 59E None LINESTRING (441.981 186.290, 441.981 189.994, ...
861 0 None AcDbEntity:AcDbPolyline None 59F None LINESTRING (441.981 193.740, 441.981 190.036, ...
862 0 None AcDbEntity:AcDbPolyline None 5A0 None LINESTRING (441.790 189.994, 441.790 190.036)
863 0 None AcDbEntity:AcDbPolyline None 5A1 None LINESTRING (441.790 190.015, 441.790 190.015)
864 0 None AcDbEntity:AcDbPolyline None 5A2 None LINESTRING (441.790 186.544, 441.790 186.544)
The whole dataset has 397.535 records. The column Iโm interested is the geometry one, which is full of Shapely LineString
objects. Even if I can plot it without issues with GeoPandas plot, I want to be able to plot the geometry column with Plotly
(since this allow me to zoom in, out, see values when hovering over the plot, etc.). However, I cannot plot the whole dataset without having VSCode or the browser (I tried Jupyter Notebook on web and also tried to open an html file generated with fig.write_html
, with no success) to crash.
This is the whole code:
import geopandas as gpd
import pandas as pd
import plotly.graph_objects as go
layout_dfs = []
test = gpd.read_file('/test_layout_file.dxf')
polyline_df = test[test.SubClasses == 'AcDbEntity:AcDbPolyline']
# polyline_df.head()
plot_data = []
for polygon in polyline_df.geometry[122:10000]:
x, y = polygon.xy
#print(y)
plot_data.append(
go.Scatter(
x=list(x[1:]),
y=list(y[1:]),
fill="toself", # Fills the polygon
mode="none", # Hides markers
showlegend=False
)
)
layout = go.Layout(
autosize=False,
width=1300,
height=800,
margin=go.layout.Margin(l=50, r=50, b=100, t=100, pad=4),
)
# Create the figure and display
fig = go.Figure(data=plot_data, layout=layout)
fig.show()