Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

86 lines
2.7KB

  1. #!/usr/bin/env python3
  2. from argparse import ArgumentParser
  3. import numpy as np
  4. import pandas as pd
  5. import geopandas as gpd
  6. import contextily as cx
  7. import matplotlib.pyplot as plt
  8. import seaborn as sns
  9. sns.set()
  10. #sns.set(font_scale=1.5)
  11. if __name__ == "__main__":
  12. parser = ArgumentParser()
  13. parser.add_argument("-f", "--file", required=True, help="Messfahrt csv")
  14. parser.add_argument("-a", "--column", required=True, help="Column to plot")
  15. parser.add_argument("-l", "--label", help="Label above the plot.")
  16. parser.add_argument("--no_legend", action="store_false", default=True, help="Do not show legend.")
  17. parser.add_argument("--save", default=None, help="Location to save pdf file.")
  18. parser.add_argument(
  19. "--show_providerinfo",
  20. default=False,
  21. help="Show providerinfo for map tiles an zoom levels.",
  22. )
  23. args = parser.parse_args()
  24. df = pd.read_csv(args.file)
  25. gdf = gpd.GeoDataFrame(
  26. df,
  27. geometry=gpd.points_from_xy(df["longitude"], df["latitude"]),
  28. crs="EPSG:4326",
  29. )
  30. gdf["srtt"] = gdf["srtt"].apply(lambda x: x / 10 ** 6)
  31. gdf["is_retranmission"] = gdf["is_retranmission"].replace(True, np.NaN).dropna().astype(float)
  32. print("Start plotting...")
  33. df_wm = gdf.to_crs(epsg=3857)
  34. ax2 = df_wm.plot()
  35. ax2 = df_wm.plot(column=args.column, cmap="hot", legend=args.no_legend, ax=ax2, legend_kwds={"label": args.label},)
  36. # ax2 = df_wm.plot.scatter(x="longitude", y="latitude", c="kmh", cmap="hot")
  37. # zoom 17 is pretty
  38. cx.add_basemap(ax2, source=cx.providers.OpenStreetMap.Mapnik, zoom=17)
  39. # gdf.plot()
  40. ax2.set_axis_off()
  41. if not args.no_legend:
  42. ax2.set_title(args.label if args.label else args.column)
  43. else:
  44. fig = ax2.figure
  45. cb_ax = fig.axes[0]
  46. cb_ax.set_label(args.label)
  47. cb_ax.tick_params(labelsize=30)
  48. if args.show_providerinfo:
  49. #####################################
  50. # Identifying how many tiles
  51. latlon_outline = gdf.to_crs("epsg:4326").total_bounds
  52. def_zoom = cx.tile._calculate_zoom(*latlon_outline)
  53. print(f"Default Zoom level {def_zoom}")
  54. cx.howmany(*latlon_outline, def_zoom, ll=True)
  55. cx.howmany(*latlon_outline, def_zoom + 1, ll=True)
  56. cx.howmany(*latlon_outline, def_zoom + 2, ll=True)
  57. # Checking out some of the other providers and tiles
  58. print(cx.providers.CartoDB.Voyager)
  59. print(cx.providers.Stamen.TonerLite)
  60. print(cx.providers.Stamen.keys())
  61. #####################################
  62. # df.plot(x="longitude", y="latitude", kind="scatter", colormap="YlOrRd")
  63. if args.save:
  64. plt.savefig("{}gps_plot.eps".format(args.save), bbox_inches="tight")
  65. else:
  66. plt.show()