|
12 | 12 | ) |
13 | 13 |
|
14 | 14 | import numpy as np |
15 | | -from matplotlib import pyplot as plt |
16 | | -from matplotlib.pyplot import figure |
17 | 15 | from pandas import DataFrame, DateOffset, Series, Timedelta |
18 | 16 |
|
19 | 17 | from pymove.core.dataframe import MoveDataFrame |
@@ -1384,223 +1382,6 @@ def get_bbox(self) -> Tuple[float, float, float, float]: |
1384 | 1382 |
|
1385 | 1383 | return bbox_ |
1386 | 1384 |
|
1387 | | - def plot_all_features( |
1388 | | - self, |
1389 | | - dtype: Optional[Callable] = np.float64, |
1390 | | - figsize: Optional[Tuple[float, float]] = (21, 15), |
1391 | | - return_fig: Optional[bool] = True, |
1392 | | - save_fig: Optional[bool] = False, |
1393 | | - name: Optional[Text] = 'features.png', |
1394 | | - ) -> Optional[figure]: |
1395 | | - """ |
1396 | | - Generate a visualization for each columns that type is equal dtype. |
1397 | | -
|
1398 | | - Parameters |
1399 | | - ---------- |
1400 | | - dtype : callable, optional |
1401 | | - Represents column type, by default np.float64 |
1402 | | - figsize : tuple(float, float), optional |
1403 | | - Represents dimensions of figure, by default (21, 15) |
1404 | | - return_fig : bool, optional |
1405 | | - Represents whether or not to return the generated picture, by default True |
1406 | | - save_fig : bool, optional |
1407 | | - Represents whether or not to save the generated picture, by default False |
1408 | | - name : str, optional |
1409 | | - Represents name of a file, by default 'features.png' |
1410 | | -
|
1411 | | - Returns |
1412 | | - ------- |
1413 | | - figure |
1414 | | - The generated picture or None |
1415 | | -
|
1416 | | - Raises |
1417 | | - ------ |
1418 | | - AttributeError |
1419 | | - If there are no columns with the specified type |
1420 | | -
|
1421 | | - """ |
1422 | | - |
1423 | | - operation = begin_operation('plot_all_features') |
1424 | | - |
1425 | | - try: |
1426 | | - col_dtype = self.select_dtypes(include=[dtype]).columns |
1427 | | - tam = col_dtype.size |
1428 | | - if not tam: |
1429 | | - raise AttributeError('No columns with dtype %s.' % dtype) |
1430 | | - |
1431 | | - fig, ax = plt.subplots(tam, 1, figsize=figsize) |
1432 | | - ax_count = 0 |
1433 | | - for col in col_dtype: |
1434 | | - ax[ax_count].set_title(col) |
1435 | | - self[col].plot(subplots=True, ax=ax[ax_count]) |
1436 | | - ax_count += 1 |
1437 | | - |
1438 | | - if save_fig: |
1439 | | - plt.savefig(fname=name, fig=fig) |
1440 | | - |
1441 | | - self.last_operation = end_operation(operation) |
1442 | | - |
1443 | | - if return_fig: |
1444 | | - return fig |
1445 | | - except Exception as e: |
1446 | | - self.last_operation = end_operation(operation) |
1447 | | - raise e |
1448 | | - |
1449 | | - def plot_trajs( |
1450 | | - self, |
1451 | | - markers: Optional[Text] = 'o', |
1452 | | - markersize: Optional[float] = 12, |
1453 | | - figsize: Optional[Tuple[float, float]] = (10, 10), |
1454 | | - return_fig: Optional[bool] = True, |
1455 | | - save_fig: Optional[bool] = False, |
1456 | | - name: Optional[Text] = 'trajectories.png', |
1457 | | - ) -> Optional[figure]: |
1458 | | - """ |
1459 | | - Generate a visualization that show trajectories. |
1460 | | -
|
1461 | | - Parameters |
1462 | | - ---------- |
1463 | | - markers : str, optional |
1464 | | - Represents visualization type marker, by default 'o' |
1465 | | - markersize : float, optional |
1466 | | - Represents visualization size marker, by default 12 |
1467 | | - figsize : tuple(float, float), optional |
1468 | | - Represents dimensions of figure, by default (10, 10) |
1469 | | - return_fig : bool, optional |
1470 | | - Represents whether or not to return the generated picture, by default True |
1471 | | - save_fig : bool, optional |
1472 | | - Represents whether or not to save the generated picture, by default False |
1473 | | - name : str, optional |
1474 | | - Represents name of a file, by default 'trajectories.png' |
1475 | | -
|
1476 | | - Returns |
1477 | | - ------- |
1478 | | - figure |
1479 | | - The generated picture or None |
1480 | | - """ |
1481 | | - |
1482 | | - operation = begin_operation('plot_trajs') |
1483 | | - |
1484 | | - fig = plt.figure(figsize=figsize) |
1485 | | - |
1486 | | - ids = self['id'].unique() |
1487 | | - for id_ in ids: |
1488 | | - self_id = self[self['id'] == id_] |
1489 | | - plt.plot( |
1490 | | - self_id[LONGITUDE], |
1491 | | - self_id[LATITUDE], |
1492 | | - markers, |
1493 | | - markersize=markersize, |
1494 | | - ) |
1495 | | - |
1496 | | - if save_fig: |
1497 | | - plt.savefig(fname=name, fig=fig) |
1498 | | - |
1499 | | - self.last_operation = end_operation(operation) |
1500 | | - |
1501 | | - if return_fig: |
1502 | | - return fig |
1503 | | - |
1504 | | - def plot_traj_id( |
1505 | | - self, |
1506 | | - tid: Union[int, Text], |
1507 | | - label: Optional[Text] = TID, |
1508 | | - feature: Optional[Text] = None, |
1509 | | - value: Optional[Any] = None, |
1510 | | - markersize: Optional[float] = 20, |
1511 | | - figsize: Optional[Tuple[float, float]] = (10, 10), |
1512 | | - return_fig: Optional[bool] = True, |
1513 | | - save_fig: Optional[bool] = False, |
1514 | | - name: Optional[Text] = None, |
1515 | | - ) -> Optional[figure]: |
1516 | | - """ |
1517 | | - Generate a visualization that shows a trajectory with the specified tid. |
1518 | | -
|
1519 | | - Parameters |
1520 | | - ---------- |
1521 | | - tid : int, str |
1522 | | - Represents the trajectory tid |
1523 | | - label : str, optional |
1524 | | - Feature with trajectories tids, by default TID |
1525 | | - feature : str, optional |
1526 | | - Name of the feature to highlight on plot, by default None |
1527 | | - value : any, optional |
1528 | | - Value of the feature to be highlighted as green marker, by default None |
1529 | | - markersize : float, optional |
1530 | | - Represents visualization size marker, by default 20 |
1531 | | - figsize : tuple(float, float), optional |
1532 | | - Represents dimensions of figure, by default (10, 10) |
1533 | | - return_fig : bool, optional |
1534 | | - Represents whether or not to return the generated picture, by default True |
1535 | | - save_fig : bool, optional |
1536 | | - Represents whether or not to save the generated picture, by default False |
1537 | | - name : str, optional |
1538 | | - Represents name of a file, by default None |
1539 | | -
|
1540 | | - Returns |
1541 | | - ------- |
1542 | | - PandasMoveDataFrame', figure |
1543 | | - Trajectory with the specified tid. |
1544 | | - The generated picture. |
1545 | | -
|
1546 | | - Raises |
1547 | | - ------ |
1548 | | - KeyError |
1549 | | - If the dataframe does not contains the TID feature |
1550 | | - IndexError |
1551 | | - If there is no trajectory with the tid passed |
1552 | | -
|
1553 | | - """ |
1554 | | - |
1555 | | - operation = begin_operation('plot_traj_id') |
1556 | | - |
1557 | | - if label not in self: |
1558 | | - self.last_operation = end_operation(operation) |
1559 | | - raise KeyError('%s feature not in dataframe' % label) |
1560 | | - |
1561 | | - df_ = self[self[label] == tid] |
1562 | | - |
1563 | | - if not len(df_): |
1564 | | - self.last_operation = end_operation(operation) |
1565 | | - raise IndexError(f'No trajectory with tid {tid} in dataframe') |
1566 | | - |
1567 | | - fig = plt.figure(figsize=figsize) |
1568 | | - |
1569 | | - plt.plot( |
1570 | | - df_.iloc[0][LONGITUDE], df_.iloc[0][LATITUDE], 'yo', markersize=markersize |
1571 | | - ) # start point |
1572 | | - plt.plot( |
1573 | | - df_.iloc[-1][LONGITUDE], df_.iloc[-1][LATITUDE], 'yX', markersize=markersize |
1574 | | - ) # end point |
1575 | | - |
1576 | | - if (not feature) or (not value) or (feature not in df_): |
1577 | | - plt.plot(df_[LONGITUDE], df_[LATITUDE]) |
1578 | | - plt.plot( |
1579 | | - df_.loc[:, LONGITUDE], df_.loc[:, LATITUDE], |
1580 | | - 'r.', markersize=markersize / 2 |
1581 | | - ) |
1582 | | - else: |
1583 | | - filter_ = df_[feature] == value |
1584 | | - df_nodes = df_.loc[filter_] |
1585 | | - df_points = df_.loc[~filter_] |
1586 | | - plt.plot(df_[LONGITUDE], df_[LATITUDE], linewidth=3) |
1587 | | - plt.plot( |
1588 | | - df_nodes[LONGITUDE], df_nodes[LATITUDE], 'gs', markersize=markersize / 2 |
1589 | | - ) |
1590 | | - plt.plot( |
1591 | | - df_points[LONGITUDE], df_points[LATITUDE], 'r.', markersize=markersize / 2 |
1592 | | - ) |
1593 | | - |
1594 | | - if save_fig: |
1595 | | - if not name: |
1596 | | - name = 'trajectory_%s.png' % tid |
1597 | | - plt.savefig(fname=name, fig=fig) |
1598 | | - |
1599 | | - self.last_operation = end_operation(operation) |
1600 | | - |
1601 | | - if return_fig: |
1602 | | - return fig |
1603 | | - |
1604 | 1385 | def show_trajectories_info(self): |
1605 | 1386 | """ |
1606 | 1387 | Show dataset information from dataframe, this is number of rows, |
|
0 commit comments