{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import plotly_express as px # import plotly.express as px\n", "import plotly.graph_objects as go\n", "import pandas as pd\n", "import numpy as np\n", "import os\n", "\n", "name = [\"NeRF\", \"PANO\", \"OURS+\", \"OURS\"]\n", "foveal = 8.0\n", "mid = 2.8\n", "far = 2.6\n", "blend = 0.1\n", "ours_full = 562\n", "pano = 1e4\n", "nerf = 9e4\n", "\n", "times = {\n", " \"fovea_l\": 0,\n", " \"mid_l\": 0,\n", " \"far_l\": 0,\n", " \"fovea_r\": 0,\n", " \"mid_r\": 0,\n", " \"far_r\": 0,\n", " \"blend\": 0,\n", " \"ours_full\": 0,\n", " \"pano\": 0,\n", " \"nerf\": 0,\n", "}\n", "clip = 0\n", "frame_id = 0\n", "\n", "\n", "def calc_total():\n", " return [\n", " times[\"nerf\"],\n", " times[\"pano\"],\n", " times[\"ours_full\"],\n", " times[\"fovea_l\"] + times[\"mid_l\"] + times[\"far_l\"] +\n", " times[\"fovea_r\"] + times[\"mid_r\"] + times[\"far_r\"] + times[\"blend\"]\n", " ]\n", "\n", "\n", "def draw_frame(*, xlim=None, **kwargs):\n", " global frame_id\n", " for key in kwargs:\n", " times[key] = kwargs[key]\n", " tot = calc_total()\n", " data = {\n", " \"fovea_l\": [0, 0, 0, times[\"fovea_l\"]],\n", " \"mid_l\": [0, 0, 0, times[\"mid_l\"]],\n", " \"far_l\": [0, 0, 0, times[\"far_l\"]],\n", " \"fovea_r\": [0, 0, 0, times[\"fovea_r\"]],\n", " \"mid_r\": [0, 0, 0, times[\"mid_r\"]],\n", " \"far_r\": [0, 0, 0, times[\"far_r\"]],\n", " \"blend\": [0, 0, 0, times[\"blend\"]],\n", " \"ours_full\": [0, 0, times[\"ours_full\"], 0],\n", " \"pano\": [0, times[\"pano\"], 0, 0],\n", " \"nerf\": [times[\"nerf\"], 0, 0, 0],\n", " }\n", " if xlim is None or xlim < max(tot) * 1.1:\n", " xlim = max(tot) * 1.1\n", " \n", " fig = go.Figure()\n", " times_keys = list(times.keys())\n", " for key in times_keys:\n", " if key == times_keys[-1]:\n", " fig.add_trace(go.Bar(\n", " y=name,\n", " x=data[key],\n", " name=key,\n", " orientation='h',\n", " text=[\"\" if item == 0 else f\"{item:.1f}\" if item < 1000 else f\"{item:.1e}\" for item in tot],\n", " textposition=\"outside\"\n", " ))\n", " else:\n", " fig.add_trace(go.Bar(\n", " y=name,\n", " x=data[key],\n", " name=key,\n", " orientation='h',\n", " ))\n", " fig.update_traces(width=0.5)\n", " fig.update_layout(barmode='stack', showlegend=False,\n", " yaxis_visible=False, yaxis_showticklabels=False, xaxis_range=[0, xlim])\n", " \n", " # fig.show()\n", " fig.write_image(f\"dynamic_bar/clip_{clip}/{frame_id:04d}.png\", width=1920 // 2, height=1080 // 2, scale=2)\n", " frame_id = frame_id + 1\n", "\n", "def add_animation(*, frames, xlim=None, **kwargs):\n", " if frames == 1:\n", " draw_frame(**kwargs, xlim=xlim)\n", " return\n", " data = {\n", " key: np.linspace(times[key], kwargs[key], frames)\n", " for key in kwargs\n", " }\n", " for i in range(frames):\n", " draw_frame(**{key: data[key][i] for key in data}, xlim=xlim)\n", "\n", "def new_clip():\n", " global clip, frame_id\n", " clip += 1\n", " frame_id = 0\n", " os.system(f\"mkdir dynamic_bar/clip_{clip}\")\n", "\n", "os.system('rm -f -r dynamic_bar')\n", "os.system('mkdir dynamic_bar')\n", "\n", "# ours mono\n", "new_clip()\n", "add_animation(fovea_l=foveal, frames=48, xlim=30) # Step 1: grow foveal\n", "add_animation(mid_l=mid, frames=16, xlim=30) # Step 2: grow mid\n", "add_animation(far_l=far, frames=16, xlim=30) # Step 3: grow far\n", "add_animation(blend=blend, frames=1, xlim=30) # Step 4: grow blend\n", "\n", "# ours stereo\n", "new_clip()\n", "add_animation(fovea_r=foveal, frames=24, xlim=30) # Step 1: grow foveal\n", "add_animation(mid_r=mid, frames=8, xlim=30) # Step 2: grow mid\n", "add_animation(far_r=far, frames=8, xlim=30) # Step 3: grow far\n", "\n", "# ours stereo adapt\n", "new_clip()\n", "add_animation(mid_r=0, far_r=0, frames=24, xlim=30)\n", "\n", "# other series\n", "new_clip()\n", "add_animation(ours_full=ours_full, frames=48, xlim=30)\n", "new_clip()\n", "add_animation(pano=pano, frames=48, xlim=30)\n", "new_clip()\n", "add_animation(nerf=nerf, frames=48, xlim=30)\n", "\n", "#os.system(f'ffmpeg -y -r 24 -i dynamic_bar/%04d.png dynamic_bar.avi')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = px.bar(\n", " df1, # 绘图数据\n", " x=list(times.keys()), # y轴\n", " y=\"name\", # x轴\n", " orientation='h', # 水平柱状图\n", " #text=[[\"a\", \"tot\"], \"tot1\", \"tot2\", {\"fovea_l\": \"\", \"blend_r\": 13.5}] # 需要显示的数据\n", ")\n", "fig.update_traces(textposition=\"outside\", showlegend=False, text=[[\"a\"]*11, [\"b\"]*11, [\"c\"]*11, [\"d\"]*11,[\"e\"]*11])\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
countrycontinentyearlifeExppopgdpPercapiso_alphaiso_num
0AfghanistanAsia195228.8018425333779.445314AFG4
1AfghanistanAsia195730.3329240934820.853030AFG4
2AfghanistanAsia196231.99710267083853.100710AFG4
3AfghanistanAsia196734.02011537966836.197138AFG4
4AfghanistanAsia197236.08813079460739.981106AFG4
...........................
1699ZimbabweAfrica198762.3519216418706.157306ZWE716
1700ZimbabweAfrica199260.37710704340693.420786ZWE716
1701ZimbabweAfrica199746.80911404948792.449960ZWE716
1702ZimbabweAfrica200239.98911926563672.038623ZWE716
1703ZimbabweAfrica200743.48712311143469.709298ZWE716
\n", "

1704 rows × 8 columns

\n", "
" ], "text/plain": [ " country continent year lifeExp pop gdpPercap iso_alpha \\\n", "0 Afghanistan Asia 1952 28.801 8425333 779.445314 AFG \n", "1 Afghanistan Asia 1957 30.332 9240934 820.853030 AFG \n", "2 Afghanistan Asia 1962 31.997 10267083 853.100710 AFG \n", "3 Afghanistan Asia 1967 34.020 11537966 836.197138 AFG \n", "4 Afghanistan Asia 1972 36.088 13079460 739.981106 AFG \n", "... ... ... ... ... ... ... ... \n", "1699 Zimbabwe Africa 1987 62.351 9216418 706.157306 ZWE \n", "1700 Zimbabwe Africa 1992 60.377 10704340 693.420786 ZWE \n", "1701 Zimbabwe Africa 1997 46.809 11404948 792.449960 ZWE \n", "1702 Zimbabwe Africa 2002 39.989 11926563 672.038623 ZWE \n", "1703 Zimbabwe Africa 2007 43.487 12311143 469.709298 ZWE \n", "\n", " iso_num \n", "0 4 \n", "1 4 \n", "2 4 \n", "3 4 \n", "4 4 \n", "... ... \n", "1699 716 \n", "1700 716 \n", "1701 716 \n", "1702 716 \n", "1703 716 \n", "\n", "[1704 rows x 8 columns]" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = px.data.gapminder()\n", "df" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.10.0 ('dvs')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.0" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "4469b029896260c1221afa6e0e6159922aafd2738570e75b7bc15e28db242604" } } }, "nbformat": 4, "nbformat_minor": 2 }