├── .github
└── workflows
│ └── static.yml
├── .gitignore
├── README.md
├── about.html
├── css
└── freelancer.css
├── data
├── multi-matshow
│ ├── particle_0.npy
│ ├── particle_1.npy
│ ├── particle_2.npy
│ ├── particle_3.npy
│ ├── particle_4.npy
│ ├── particle_5.npy
│ ├── velocity_0.npy
│ ├── velocity_1.npy
│ ├── velocity_2.npy
│ ├── velocity_3.npy
│ ├── velocity_4.npy
│ └── velocity_5.npy
├── single-3dplot-2.npy
├── single-scatter-4-adap-x.npy
├── single-scatter-4-adap-y.npy
├── single-scatter-4-value.npy
├── single-scatter-5-hist.npy
└── single-scatter-5-pred.npy
├── fig
├── multi-matshow.jpg
├── readme
│ ├── homepage.png
│ ├── single-linear-1-page.png
│ └── title-image.png
├── single-3dplot-1.jpg
├── single-3dplot-2.jpg
├── single-hist-horizon.jpg
├── single-hist-vertical.jpg
├── single-linear-1.jpg
├── single-linear-2.jpg
├── single-linear-3.jpg
├── single-scatter-1.jpg
├── single-scatter-2.jpg
├── single-scatter-3.jpg
├── single-scatter-4.jpg
├── single-scatter-5.jpg
└── utils
│ └── court.png
├── index.html
├── js
├── contact_me.js
├── freelancer.min.js
└── jqBootstrapValidation.js
├── notebook
├── multi-matshow.ipynb
├── single-3dplot.ipynb
├── single-hist.ipynb
├── single-linear.ipynb
└── single-scatter.ipynb
├── pages
├── multi-matshow.html
├── single-3dplot-1.html
├── single-3dplot-2.html
├── single-hist-horizontal.html
├── single-hist-vertical.html
├── single-lineplot-1.html
├── single-lineplot-2.html
├── single-lineplot-3.html
├── single-scatter-1.html
├── single-scatter-2.html
├── single-scatter-3.html
├── single-scatter-4.html
└── single-scatter-5.html
├── posts.html
└── vendor
├── bootstrap
├── css
│ └── bootstrap.min.css
└── js
│ └── bootstrap.min.js
├── font-awesome
├── css
│ └── font-awesome.min.css
└── fonts
│ └── fontawesome-webfont.woff2
└── jquery
└── jquery.min.js
/.github/workflows/static.yml:
--------------------------------------------------------------------------------
1 | # Simple workflow for deploying static content to GitHub Pages
2 | name: matplotlib-prefab
3 |
4 | on:
5 | # Runs on pushes targeting the default branch
6 | push:
7 | branches: ["main"]
8 |
9 | # Allows you to run this workflow manually from the Actions tab
10 | workflow_dispatch:
11 |
12 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13 | permissions:
14 | contents: read
15 | pages: write
16 | id-token: write
17 |
18 | # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19 | # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20 | concurrency:
21 | group: "pages"
22 | cancel-in-progress: false
23 |
24 | jobs:
25 | # Single deploy job since we're just deploying
26 | deploy:
27 | environment:
28 | name: github-pages
29 | url: ${{ steps.deployment.outputs.page_url }}
30 | runs-on: ubuntu-latest
31 | steps:
32 | - name: Checkout
33 | uses: actions/checkout@v3
34 | - name: Setup Pages
35 | uses: actions/configure-pages@v3
36 | - name: Upload artifact
37 | uses: actions/upload-pages-artifact@v2
38 | with:
39 | # Upload entire repository
40 | path: '.'
41 | - name: Deploy to GitHub Pages
42 | id: deployment
43 | uses: actions/deploy-pages@v2
44 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | Matplotlib Prefab is a repository based on matplotlib package, which provides several matplotlib ploting templates for *line plot*, *hist plot*, *scatter plot*, and some complex plottings. You can check the website at [cbhua.github.io/matplotlib-prefab](https://cbhua.github.io/matplotlib-prefab/).
4 |
5 | ### 💡 Introduction
6 |
7 | I have a passion for creating visually appealing figures in publications. During my time writing papers, I often dedicated significant effort to crafting plots. In this repository, I've compiled some of my previous `matplotlib` plotting source code and have designed several templates for convenient reuse. I've chosen not to package this content due to the myriad of customizable parameters. Instead, I believe a template approach is more straightforward to modify and repurpose. I hope these templates inspire you and provide techniques to craft beautiful `matplotlib` figures.
8 |
9 | ### ⚙️ Environment
10 |
11 | I've aimed to keep dependencies to a minimum; thus, a basic combination of `matplotlib` and `numpy` should suffice. However, it's important to note that I've incorporated LaTeX font families and formatting. Therefore, you'll need to have [LaTeX](https://www.latex-project.org/get/) installed on your operating system.
12 |
13 | ```
14 | Python Version: 3.10 (develop)
15 | Python Package: matplotlib 3.8 (support Latex text), numpy
16 | Other: to use the Latex illustration style, the Latex is required to be installed
17 | ```
18 |
19 | ### 🔦 How to use
20 |
21 | You can easily go to the website: [cbhua.github.io/matplotlib-prefab](https://cbhua.github.io/matplotlib-prefab/) and see the example figures of each prefabs:
22 |
23 |
24 |
25 | You can click on the figure to view the associated template code. Most of the code for these figures is self-contained and can be run independently. However, a few require external data. For those instances, please refer to the accompanying notebook.
26 |
27 |
28 |
29 | You can also refer to the `notebook` directory to access Jupyter notebooks for those example figures and tailor them to your needs.
30 |
31 | ### 🔧 Structure
32 |
33 | ```
34 | .
35 | ├── css - webpage
36 | ├── js - webpage
37 | ├── pages - webpage
38 | ├── vendor - webpage
39 | ├── data - some complex figures reauqired external data
40 | ├── fig - example figures
41 | ├── notebook - jupyter notebook for creating figures
42 | └── *.html - webpage
43 | ```
44 |
45 | ### 🖼 Visualization Example
46 |
47 | **Line Plots**: [Jupyter notebook](https://github.com/cbhua/matplotlib-prefab/blob/main/notebook/single-linear.ipynb)
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | **Hist Plots**: [Jupyter notebook](https://github.com/cbhua/matplotlib-prefab/blob/main/notebook/single-hist.ipynb)
56 |
57 |
58 |
59 |
60 |
61 | **Scatter Plots**: [Jupyter notebook](https://github.com/cbhua/matplotlib-prefab/blob/main/notebook/single-scatter.ipynb)
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | **Complex Examples**: [3D Plots jupyter notebook](https://github.com/cbhua/matplotlib-prefab/blob/main/notebook/single-3dplot.ipynb), [Matshow jupyter notebook](https://github.com/cbhua/matplotlib-prefab/blob/main/notebook/multi-matshow.ipynb)
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | ### 📬 Contact
82 |
83 | If you have any question or find any bug, feel free to raise an issue. If you have ideas to contribute to this repo, welcome to pull request or contact cbhua@kaist.ac.kr. Thanks for interested to our work!
84 |
--------------------------------------------------------------------------------
/about.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
79 | Matplotlib Prefab is a repository based on matplotlib package, which provides several matplotlib ploting templates for line plot, 80 | hist plot, scatter plot, and some complex plottings. You can see the GitHub repository at https://github.com/cbhua/matplotlib-prefab. 81 |
82 |85 | I have a passion for creating visually appealing figures in publications. During my time writing papers, I often dedicated significant effort to crafting plots. 86 | In this repository, I've compiled some of my previous `matplotlib` plotting source code and have designed several templates for convenient reuse. 87 | I've chosen not to package this content due to the myriad of customizable parameters. Instead, I believe a template approach is more straightforward to modify and repurpose. 88 | I hope these templates inspire you and provide techniques to craft beautiful `matplotlib` figures. 89 |
90 |
93 | I've aimed to keep dependencies to a minimum; thus, a basic combination of matplotlib
and numpy
should suffice. However, it's important to note that I've incorporated LaTeX font families and formatting.
94 | Therefore, you'll need to have LaTeX installed on your operating system.
95 |
97 | Python Version: 3.10 (develop)
98 | Python Package: matplotlib 3.8 (support Latex text), numpy
99 | Other: to use the Latex illustration style, the Latex is required to be installed
100 |
101 | 104 | You can easily go to the home page: cbhua.github.io/matplotlib-prefab and see the example figures of each prefabs: 105 |
106 |108 | You can click on the figure to view the associated template code. Most of the code for these figures is self-contained and can be run independently. However, a few require external data. For those instances, please refer to the accompanying notebook. 109 |
110 |
112 | You can also refer to the GitHub notebook
directory to access Jupyter notebooks for those example figures and tailor them to your needs.
113 |
115 | Have fun! 116 |
117 |
80 | # Packages
81 | import numpy as np
82 | import matplotlib.pyplot as plt
83 | import seaborn as sns
84 | from matplotlib import cm
85 |
86 | # Use LaTeX font
87 | plt.rcParams.update({'text.usetex': True})
88 |
89 | # Figure font config
90 | label_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
91 | title_font = {'fontfamily': 'Arial Black', 'fontsize': 16}
92 | legend_font = {'family': 'Palatino Linotype', 'size': 12}
93 | text_font = {'family': 'Palatino Linotype', 'size': 12}
94 |
95 | # Load data
96 | particle = []
97 | velocity = []
98 | for i in range(6):
99 | particle.append(np.load('../data/multi-matshow/particle_' + str(i) + '.npy'))
100 | velocity.append(np.load('../data/multi-matshow/velocity_' + str(i) + '.npy')) X-4)**2 + (8 * Y - 4)**2))
101 |
102 | # Plot
103 | fig, axs = plt.subplots(2, 3, figsize=(8, 6))
104 |
105 | for idx in range(6):
106 | i = idx // 3
107 | j = idx % 3
108 |
109 | for particle_idx, (x, y) in enumerate(zip(particle[idx][:, 0], particle[idx][:, 1])):
110 | axs[i, j].scatter(
111 | x, y,
112 | marker='o',
113 | color=cm.RdYlBu_r(velocity[idx][particle_idx])
114 | )
115 |
116 | # Label and title
117 | axs[i, j].get_xaxis().set_visible(False)
118 | axs[i, j].get_yaxis().set_visible(False)
119 | axs[i, j].set_title(f'$t={idx}$', fontdict=title_font)
120 |
121 | # Axis range
122 | axs[i, j].set_xlim([0.5, 5.5])
123 | axs[i, j].set_ylim([0.5, 4])
124 |
125 | plt.tight_layout()
126 | plt.savefig('../fig/multi-matshow.jpg', dpi=300)
127 |
128 |
144 |
80 | # Packages
81 | import numpy as np
82 | import matplotlib.pyplot as plt
83 | from matplotlib import cm
84 |
85 | # Use LaTeX font
86 | plt.rcParams.update({'text.usetex': True})
87 |
88 | # Figure font config
89 | label_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
90 | title_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
91 |
92 | # Generate data
93 | X = np.linspace(0, 1, num=256, endpoint=True)
94 | Y = np.linspace(0, 1, num=256, endpoint=True)
95 | X, Y = np.meshgrid(X, Y)
96 | R = np.sqrt(1 * ((8 * X-4)**2 + (8 * Y - 4)**2))
97 | Z = 0.5 * np.sin(R)
98 |
99 | # Plot
100 | ax = plt.figure(figsize=(8, 6)).add_subplot(projection='3d')
101 |
102 | surf = ax.plot_surface(
103 | X, Y, Z,
104 | cmap=cm.coolwarm,
105 | linewidth=1,
106 | antialiased=False,
107 | alpha=0.3
108 | )
109 | contour = ax.contour(
110 | X, Y, Z,
111 | zdir='z',
112 | levels=8,
113 | offset=-1,
114 | cmap=cm.coolwarm,
115 | alpha=0.4
116 | )
117 |
118 | ax.set_xlim(0, 1)
119 | ax.set_ylim(0, 1)
120 | ax.set_zlim(-1, 0.5)
121 |
122 | ax.set_xlabel('x', fontdict=label_font)
123 | ax.set_ylabel('y', fontdict=label_font)
124 | ax.set_zlabel('z', fontdict=label_font)
125 | ax.set_title(
126 | r'Ground Truth for $u(x, y) = \mathrm{sin}(((8x-4)^2+(8y-4)^2)^{1/2})$',
127 | fontdict=title_font
128 | )
129 |
130 | ax.tick_params(axis='both', which='major', labelsize=12)
131 | ax.tick_params(axis='both', which='minor', labelsize=12)
132 |
133 | labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
134 | [label.set_fontname('serif') for label in labels]
135 |
136 | plt.tight_layout()
137 | plt.savefig('../fig/single-3dplot-1.jpg', dpi=300)
138 |
139 |
155 |
80 | # Packages
81 | import numpy as np
82 | import matplotlib.pyplot as plt
83 | from matplotlib import cm
84 |
85 | # Use LaTeX font
86 | plt.rcParams.update({'text.usetex': True})
87 |
88 | # Figure font config
89 | label_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
90 | title_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
91 |
92 | # Load data
93 | value = np.load('../data/single-3dplot-2.npy')
94 |
95 | x, y, z = np.meshgrid(
96 | np.linspace(0, 1, num=64, endpoint=True),
97 | np.linspace(0, 1, num=64, endpoint=True),
98 | np.linspace(0, 1, num=64, endpoint=True)
99 | )
100 |
101 | # Plot
102 | ax = plt.figure(figsize=(6, 6)).add_subplot(projection='3d')
103 | ax.scatter(x, y, z, s=3, c=value, cmap=cm.inferno, alpha=0.1)
104 |
105 | ax.set_xlabel('x', fontdict=label_font)
106 | ax.set_ylabel('y', fontdict=label_font)
107 | ax.set_zlabel('z', fontdict=label_font)
108 | ax.set_title('Single 3D Plot 2', fontdict=title_font)
109 |
110 | ax.tick_params(axis='both', which='major', labelsize=12)
111 | ax.tick_params(axis='both', which='minor', labelsize=12)
112 |
113 | labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
114 | [label.set_fontname('serif') for label in labels]
115 |
116 | plt.tight_layout()
117 | plt.savefig('../fig/single-3dplot-2.jpg', dpi=300)
118 |
119 |
135 |
80 | # Packages
81 | import numpy as np
82 | import matplotlib.pyplot as plt
83 | from matplotlib import cm
84 |
85 | # Use LaTeX font
86 | plt.rcParams.update({'text.usetex': True})
87 |
88 | # Figure font config
89 | label_font = {'fontfamily': 'Arial Black', 'fontsize': 12}
90 | title_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
91 | text_font = {'family': 'Palatino Linotype', 'fontsize': 12}
92 | legend_font = {'family': 'Palatino Linotype', 'size': 12}
93 |
94 | # Generate data
95 | item = [
96 | 'Model 1',
97 | 'Model 2',
98 | 'Model 3',
99 | 'Model 4',
100 | 'Model 5',
101 | ]
102 |
103 | value = np.array([
104 | [1, 1.5, 2, 2.5, 3],
105 | [0.2, 0.4, 0.6, 0.8, 1],
106 | [0.1, 0.1, 0.1, 0.1, 0.1]
107 | ])
108 |
109 | std = np.array([
110 | [0.1, 0.15, 0.2, 0.25, 0.3],
111 | [0.05, 0.05, 0.05, 0.05, 0.05],
112 | [0, 0, 0, 0, 0]
113 | ])
114 |
115 | # Plot
116 | fig, ax = plt.subplots( 1, figsize=(4, 4))
117 |
118 | # Config
119 | height = 0.5
120 |
121 | ax.barh(
122 | item, value[0], xerr=std[0],
123 | height=height,
124 | color=cm.Set2(0),
125 | label='Value 1',
126 | capsize=2,
127 | )
128 | ax.barh(
129 | item, value[1], xerr=std[1],
130 | left=value[0],
131 | height=height,
132 | color=cm.Set2(1),
133 | label='Value 2'
134 | )
135 | ax.barh(
136 | item, value[2], xerr=std[2],
137 | left=value[0] + value[1],
138 | height=height,
139 | color=cm.Set2(2),
140 | label='Value 2'
141 | )
142 |
143 | # Label and title
144 | ax.set_xlabel('X Label', **label_font)
145 | ax.set_title('Single Hist Plot (Horizontal)', **title_font)
146 |
147 | # Legend
148 | ax.legend(loc='lower right', prop=legend_font)
149 |
150 | # Axis
151 | ax.tick_params(axis='both', which='major', labelsize=12)
152 |
153 | # Grid
154 | ax.grid(axis='both', color='black', alpha=0.1)
155 |
156 | plt.tight_layout()
157 | plt.savefig('../fig/single-hist-horizon.jpg', dpi=300)
158 |
159 |
175 |
80 | # Packages
81 | import numpy as np
82 | import matplotlib.pyplot as plt
83 | from matplotlib import cm
84 |
85 | # Use LaTeX font
86 | plt.rcParams.update({'text.usetex': True})
87 |
88 | # Figure font config
89 | label_font = {'fontfamily': 'Arial Black', 'fontsize': 12}
90 | title_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
91 | text_font = {'family': 'Palatino Linotype', 'fontsize': 12}
92 | legend_font = {'family': 'Palatino Linotype', 'size': 12}
93 |
94 | # Generate data
95 | item = [
96 | 'Model 1',
97 | 'Model 2',
98 | 'Model 3',
99 | 'Model 4',
100 | 'Model 5',
101 | ]
102 |
103 | value = np.array([
104 | [1, 1.5, 2, 2.5, 3],
105 | [0.2, 0.4, 0.6, 0.8, 1],
106 | [0.1, 0.1, 0.1, 0.1, 0.1]
107 | ])
108 |
109 | std = np.array([
110 | [0.1, 0.15, 0.2, 0.25, 0.3],
111 | [0.05, 0.05, 0.05, 0.05, 0.05],
112 | [0, 0, 0, 0, 0]
113 | ])
114 |
115 | # Plot
116 | fig, ax = plt.subplots(1, figsize=(4, 4))
117 |
118 | # Color list
119 | color = [cm.Set2(1)] + [cm.Set2(0)] * 4
120 |
121 | ax.bar(
122 | item, value[0], yerr=std[0],
123 | width=0.65,
124 | color=color,
125 | capsize=2,
126 | )
127 |
128 | # Label and title
129 | ax.set_ylabel('Y Label', **label_font)
130 | ax.set_title('Single Hist Plot (Vertical)', **title_font)
131 |
132 | # Axis
133 | ax.tick_params(axis='both', which='major', labelsize=12)
134 |
135 | # Grid
136 | ax.grid(axis='both', color='black', alpha=0.1)
137 |
138 | plt.tight_layout()
139 | plt.savefig('../fig/single-hist-vertical.jpg', dpi=300)
140 |
141 |
157 |
80 | # Packages
81 | import numpy as np
82 | import matplotlib.pyplot as plt
83 | from matplotlib import cm
84 |
85 | # Use LaTeX font
86 | plt.rcParams.update({'text.usetex': True})
87 |
88 | # Figure font config
89 | label_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
90 | title_font = {'fontfamily': 'Arial Black', 'fontsize': 16}
91 | legend_font = {'family': 'Palatino Linotype', 'size': 12}
92 | text_font = {'family': 'Palatino Linotype', 'size': 12}
93 |
94 | # Generate data
95 | x = np.linspace(0, 10, 100)
96 | y1 = x ** 2
97 | y2 = x ** 2 * np.log(x)
98 | y3 = x ** 3
99 |
100 | fig, ax = plt.subplots(1, figsize=(4, 4))
101 |
102 | ax.plot(x, y1, color=cm.Set2(0), linestyle='-', linewidth=2)
103 | ax.plot(x, y2, color=cm.Set2(1), linestyle='-.', linewidth=2)
104 | ax.plot(x, y3, color='gray', linestyle='--', linewidth=2)
105 |
106 | # Label and title
107 | ax.set_xlabel('X Lable', fontdict=label_font)
108 | ax.set_ylabel('Y Lable', fontdict=label_font)
109 | ax.set_title('Single Line Plot 1', fontdict=title_font)
110 |
111 | # Text info
112 | ax.text(
113 | 4, 180,
114 | r'$O(n^3)$' + '\n(Method 1)',
115 | fontdict=text_font,
116 | color='gray',
117 | verticalalignment='center',
118 | horizontalalignment='center'
119 | )
120 | ax.text(
121 | 7.3, 180,
122 | r'$O(n^2)\mathrm{log}n$' + '\n(Method 2)',
123 | fontdict=text_font,
124 | color=cm.Set2(1),
125 | verticalalignment='center',
126 | horizontalalignment='center'
127 | )
128 | ax.text(
129 | 8, 25,
130 | r'$O(n^2)$' + '\n(Method 3)',
131 | fontdict=text_font,
132 | color=cm.Set2(0),
133 | verticalalignment='center',
134 | horizontalalignment='center'
135 | )
136 |
137 | # Ticks fontsize and font family
138 | ax.tick_params(axis='both', which='major', labelsize=14)
139 | labels = ax.get_xticklabels() + ax.get_yticklabels()
140 | [label.set_fontname('serif') for label in labels]
141 |
142 | # Axis range
143 | ax.set_xlim(0, 10)
144 | ax.set_ylim(0, 200)
145 |
146 | # Grid
147 | ax.grid(axis='both', color='black', alpha=0.1)
148 |
149 | plt.tight_layout()
150 | plt.savefig('../fig/single-linear-1.jpg', dpi=300)
151 |
152 |
168 |
80 | # Packages
81 | import numpy as np
82 | import matplotlib.pyplot as plt
83 | from matplotlib import cm
84 |
85 | # Use LaTeX font
86 | plt.rcParams.update({'text.usetex': True})
87 |
88 | # Figure font config
89 | label_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
90 | title_font = {'fontfamily': 'Arial Black', 'fontsize': 16}
91 | legend_font = {'family': 'Palatino Linotype', 'size': 12}
92 | text_font = {'family': 'Palatino Linotype', 'size': 12}
93 |
94 | # Generate data
95 | x = np.linspace(0, 10, 100) + 1
96 |
97 | # Line plot
98 | y1_mean = 1/x
99 | y1_std = 0.3/x
100 | y2_mean = 0.6/x
101 | y2_std = 0.1/x
102 |
103 | fig, ax = plt.subplots(1, figsize=(4, 4))
104 |
105 | ax.plot(x, y1_mean, label='Model 1 Loss', color=cm.Set2(0), linestyle='-', linewidth=2)
106 | ax.plot(x, y2_mean, label='Model 2 Loss', color=cm.Set2(1), linestyle='-', linewidth=2)
107 | ax.fill_between(x, y1_mean - y1_std, y1_mean + y1_std, color=cm.Set2(0), alpha=0.2)
108 | ax.fill_between(x, y2_mean - y2_std, y2_mean + y2_std, color=cm.Set2(1), alpha=0.2)
109 |
110 | # Label and title
111 | ax.set_xlabel('X Lable', fontdict=label_font)
112 | ax.set_ylabel('Y Lable', fontdict=label_font)
113 | ax.set_title('Single Line Plot 2', fontdict=title_font)
114 |
115 | # Legend
116 | ax.legend(loc='upper right', prop=legend_font)
117 |
118 | # Ticks fontsize and font family
119 | ax.tick_params(axis='both', which='major', labelsize=14)
120 | labels = ax.get_xticklabels() + ax.get_yticklabels()
121 | [label.set_fontname('serif') for label in labels]
122 |
123 | # Axis range
124 | ax.set_xlim(1, 11)
125 | ax.set_ylim(0, 1)
126 |
127 | # Grid
128 | ax.grid(axis='both', color='black', alpha=0.1)
129 |
130 | plt.tight_layout()
131 | plt.savefig('../fig/single-linear-2.jpg', dpi=300)
132 |
133 |
149 |
80 | # Packages
81 | import numpy as np
82 | import matplotlib.pyplot as plt
83 | from matplotlib import cm
84 |
85 | # Use LaTeX font
86 | plt.rcParams.update({'text.usetex': True})
87 |
88 | # Figure font config
89 | label_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
90 | title_font = {'fontfamily': 'Arial Black', 'fontsize': 16}
91 | legend_font = {'family': 'Palatino Linotype', 'size': 12}
92 | text_font = {'family': 'Palatino Linotype', 'size': 12}
93 |
94 | # Generate data
95 | x = np.linspace(0, 10, 100)
96 | x11 = np.linspace(0, 5, 50)
97 | x12 = np.linspace(5, 10, 50)
98 |
99 | # Line plot
100 | y1 = x * (x - 5) * (x - 10)
101 | y2 = 0.25 * x * (x - 2.5) * (x - 10)
102 | y3 = 0.25 * x11 * (x11 - 7.5) * (x11 - 10)
103 | y4 = 0.25 * x12 * (x12 - 7.5) * (x12 - 10)
104 |
105 | # Scatter nodes
106 | x2 = [0, 2.5, 5, 7.5, 10]
107 | x3 = np.linspace(0, 10, 10)
108 |
109 | fig, ax = plt.subplots(1, figsize=(6, 3))
110 |
111 | ax.plot(x, y1, color=cm.Set2(0), label='Model 1', linestyle='-', linewidth=2)
112 | ax.plot(x, y2, color=cm.Set2(1), label='Model 2', linestyle='-.', linewidth=2)
113 |
114 | ax.plot(x11, y3, color=cm.Set2(2), label='Model 3(1)', linestyle='--', linewidth=2)
115 | ax.plot(x12, y4, color=cm.Set2(3), label='Model 3(2)', linestyle='--', linewidth=2)
116 | ax.plot([5, 5], [-50, 50], color='gray', linestyle='--', linewidth=1)
117 |
118 | # Fill between line and y=0
119 | ax.fill_between(x, y1, 0, color=cm.Set2(0), alpha=0.1)
120 | ax.fill_between(x, y2, 0, color=cm.Set2(1), alpha=0.1)
121 |
122 | # Scatter nodes
123 | ax.scatter(x2, [0] * len(x2), label='Node 1', color=cm.Set1(1), marker='o', s=30)
124 | ax.scatter(x3, [0] * len(x3), label='Node 2', color='gray', marker='x', s=50)
125 |
126 | # Legend
127 | handles, labels = ax.get_legend_handles_labels()
128 | fig.legend(handles, labels, loc='center left', ncol=1, bbox_to_anchor=(0.98, 0.5), prop=legend_font)
129 |
130 | # Label and title
131 | ax.set_xlabel('X Lable', fontdict=label_font)
132 | ax.set_ylabel('Y Lable', fontdict=label_font)
133 | ax.set_title('Single Line Plot 3', fontdict=title_font)
134 |
135 | # Ticks fontsize and font family
136 | ax.tick_params(axis='both', which='major', labelsize=14)
137 | labels = ax.get_xticklabels() + ax.get_yticklabels()
138 | [label.set_fontname('serif') for label in labels]
139 |
140 | # Axis range
141 | ax.set_xlim(0, 10)
142 | ax.set_ylim(-50, 50)
143 |
144 | # Grid
145 | ax.grid(axis='both', color='black', alpha=0.1)
146 |
147 | plt.tight_layout()
148 | plt.savefig('../fig/single-linear-3.jpg', dpi=300, bbox_inches='tight')
149 |
150 |
166 |
80 | # Packages
81 | import numpy as np
82 | import matplotlib.pyplot as plt
83 | from matplotlib import cm
84 |
85 | # Use LaTeX font
86 | plt.rcParams.update({'text.usetex': True})
87 |
88 | # Figure font config
89 | label_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
90 | title_font = {'fontfamily': 'Arial Black', 'fontsize': 16}
91 | legend_font = {'family': 'Palatino Linotype', 'size': 10}
92 | text_font = {'family': 'Palatino Linotype', 'fontsize': 12}
93 |
94 | # Generate data
95 | x = [1, 2, 3, 4, 5]
96 | y = [5, 4, 3, 2, 1]
97 |
98 | label_list = ['Label 1', 'Label 2', 'Label 3', 'Label 4', 'Label 5']
99 | marker_list = ['o', '^', 'P', '*', 's']
100 |
101 | # Plot
102 | fig, ax = plt.subplots(1, figsize=(4, 4))
103 |
104 | for i in range(len(x)):
105 | ax.scatter(
106 | x[i], y[i],
107 | color=cm.Set2(i),
108 | marker=marker_list[i],
109 | s=80
110 | )
111 | if i < 4:
112 | ax.text(
113 | x[i] + 0.3, y[i],
114 | label_list[i],
115 | fontdict=text_font,
116 | color=cm.Set2(i),
117 | verticalalignment='center',
118 | horizontalalignment='left'
119 | )
120 | else:
121 | ax.text(
122 | x[i] - 0.3, y[i],
123 | label_list[i],
124 | fontdict=text_font,
125 | color=cm.Set2(i),
126 | verticalalignment='center',
127 | horizontalalignment='right'
128 | )
129 |
130 | # Label and title
131 | ax.set_xlabel('X Lable', fontdict=label_font)
132 | ax.set_ylabel('Y Lable', fontdict=label_font)
133 | ax.set_title('Single Scatter Plot 1', fontdict=title_font)
134 |
135 | # Ticks fontsize and font family
136 | ax.tick_params(axis='both', which='major', labelsize=14)
137 | labels = ax.get_xticklabels() + ax.get_yticklabels()
138 | [label.set_fontname('serif') for label in labels]
139 |
140 | # Grid
141 | ax.grid(axis='both', color='black', alpha=0.1)
142 |
143 | plt.tight_layout()
144 | plt.savefig('../fig/single-scatter-1.jpg', dpi=300)
145 |
146 |
162 |
80 | # Packages
81 | import numpy as np
82 | import matplotlib.pyplot as plt
83 | from matplotlib import cm
84 |
85 | # Use LaTeX font
86 | plt.rcParams.update({'text.usetex': True})
87 |
88 | # Figure font config
89 | label_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
90 | title_font = {'fontfamily': 'Arial Black', 'fontsize': 16}
91 | legend_font = {'family': 'Palatino Linotype', 'size': 10}
92 | text_font = {'family': 'Palatino Linotype', 'fontsize': 12}
93 |
94 | # Generate data
95 | depot = [0.5, 0.5]
96 | nodes_x, nodes_y = np.meshgrid(
97 | np.linspace(0, 1, 4),
98 | np.linspace(0, 1, 4)
99 | )
100 | node_prob = np.random.rand(4, 4)
101 | routing_x = [
102 | [0.5, 0, 0, 0.33, 0.5],
103 | [0.5, 0.66, 1, 1, 0.5],
104 | [0.5, 1, 1, 0.66, 0.5],
105 | [0.5, 0.33, 0, 0, 0.5]
106 | ]
107 | routing_y = [
108 | [0.5, 0.66, 1, 1, 0.5],
109 | [0.5, 1, 1, 0.66, 0.5],
110 | [0.5, 0.33, 0, 0, 0.5],
111 | [0.5, 0, 0, 0.33, 0.5]
112 | ]
113 |
114 | # Plot
115 | fig, ax = plt.subplots(1, figsize=(4, 4))
116 |
117 | # Scatter node
118 | ax.scatter(
119 | nodes_x, nodes_y,
120 | edgecolors='gray',
121 | facecolors='none',
122 | marker='o',
123 | linewidths=2,
124 | s=50
125 | )
126 | ax.scatter(
127 | depot[0], depot[1],
128 | color=cm.Set2(1),
129 | marker='s',
130 | s=80
131 | )
132 |
133 | # Plot node probability bar & text
134 | for idx, (x, y) in enumerate(zip(nodes_x.flatten(), nodes_y.flatten())):
135 | prob = node_prob[idx // 4][idx % 4]
136 | ax.add_patch(
137 | plt.Rectangle(
138 | (x - 0.005, y + 0.02),
139 | 0.01,
140 | prob * 0.05,
141 | edgecolor='gray',
142 | facecolor='gray',
143 | fill=True,
144 | )
145 | )
146 | ax.text(
147 | x, y - 0.025,
148 | f"{prob:.2f}",
149 | horizontalalignment="center",
150 | verticalalignment="top",
151 | fontsize=10,
152 | color='gray',
153 | )
154 |
155 | # Text depot
156 | ax.text(
157 | depot[0], depot[1] - 0.025,
158 | f"Depot",
159 | horizontalalignment="center",
160 | verticalalignment="top",
161 | fontsize=10,
162 | color=cm.Set2(1),
163 | )
164 |
165 | # Plot routing
166 | for routing_idx in range(4):
167 | for path_idx in range(4):
168 | src_x = routing_x[routing_idx][path_idx]
169 | src_y = routing_y[routing_idx][path_idx]
170 | dst_x = routing_x[routing_idx][path_idx + 1]
171 | dst_y = routing_y[routing_idx][path_idx + 1]
172 | ax.annotate(
173 | "",
174 | xy=(dst_x, dst_y),
175 | xytext=(src_x, src_y),
176 | arrowprops=dict(
177 | arrowstyle="-|>",
178 | color=cm.Set2(routing_idx),
179 | lw=1.2,
180 | ),
181 | size=15,
182 | annotation_clip=False,
183 | )
184 |
185 | # Axis range
186 | ax.set_xlim(-0.1, 1.1)
187 | ax.set_ylim(-0.1, 1.1)
188 |
189 | # Label and title
190 | ax.set_xlabel('X Lable', fontdict=label_font)
191 | ax.set_ylabel('Y Lable', fontdict=label_font)
192 | ax.set_title('Single Scatter Plot 2', fontdict=title_font)
193 |
194 | # Ticks fontsize and font family
195 | ax.tick_params(axis='both', which='major', labelsize=14)
196 | labels = ax.get_xticklabels() + ax.get_yticklabels()
197 | [label.set_fontname('serif') for label in labels]
198 |
199 | # Grid
200 | ax.grid(axis='both', color='black', alpha=0.1)
201 |
202 | plt.tight_layout()
203 | plt.savefig('../fig/single-scatter-2.jpg', dpi=300)
204 |
205 |
221 |
80 | # Packages
81 | import numpy as np
82 | import matplotlib.pyplot as plt
83 | from matplotlib import cm
84 |
85 | # Use LaTeX font
86 | plt.rcParams.update({'text.usetex': True})
87 |
88 | # Figure font config
89 | label_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
90 | title_font = {'fontfamily': 'Arial Black', 'fontsize': 16}
91 | legend_font = {'family': 'Palatino Linotype', 'size': 10}
92 | text_font = {'family': 'Palatino Linotype', 'fontsize': 12}
93 |
94 | # Generate data
95 | x = np.linspace(0, 1, 10)
96 | y1 = [0.55] * 6 + [0.65, 0.80, 0.95, 1.2]
97 | y2 = [0.45] * 6 + [0.35, 0.20, 0.05, -0.2]
98 |
99 | y1 = np.array(y1)
100 | y2 = np.array(y2)
101 |
102 | err1_x = np.random.rand(10) * 0.05 - 0.025
103 | err1_y = np.random.rand(10) * 0.05 - 0.025
104 | err2_x = np.random.rand(10) * 0.05 - 0.025
105 | err2_y = np.random.rand(10) * 0.05 - 0.025
106 |
107 | # Plot
108 | import matplotlib.patches as patches
109 |
110 | fig, ax = plt.subplots(1, figsize=(3, 3))
111 |
112 | # Plot history
113 | ax.plot( x[:4], y1[:4], label='History', color=cm.Set2(2), marker='o', lw=2, markersize=5)
114 | ax.plot( x[:4], y2[:4], color=cm.Set2(2), marker='o', lw=2, markersize=5)
115 |
116 | # Plot future ground truth
117 | ax.plot( x[4:], y1[4:], label='Future GT', color=cm.Set2(1), marker='o', lw=2, markersize=5)
118 | ax.plot( x[4:], y2[4:], color=cm.Set2(1), marker='o', lw=2, markersize=5)
119 |
120 | # Connection
121 | ax.plot( [x[3], x[4]], [y1[3], y1[4]], color=cm.Set2(1), lw=2, ls='-')
122 | ax.plot( [x[3], x[4]], [y2[3], y2[4]], color=cm.Set2(1), lw=2, ls='-')
123 |
124 | # Plot future prediction
125 | ax.plot(x[4:]+err1_x[4:], y1[4:]+err1_y[4:], label='Future Pred', color=cm.Set2(0), marker='o', lw=2, markersize=5)
126 | ax.plot(x[4:]+err2_x[4:], y2[4:]+err2_y[4:], color=cm.Set2(0), marker='o', lw=2, markersize=5)
127 |
128 | # Connection
129 | ax.plot([x[3], x[4]+err1_x[4]], [y1[3], y1[4]+err1_y[4]], color=cm.Set2(0), lw=2, ls='-')
130 | ax.plot([x[3], x[4]+err2_x[4]], [y2[3], y2[4]+err2_y[4]], color=cm.Set2(0), lw=2, ls='-')
131 |
132 | # Add map items
133 | ax.add_patch(patches.Rectangle((-0.1, 0.6), 0.6, 0.6, edgecolor='grey',
134 | facecolor='lightgrey', lw=1, fill=True,))
135 | ax.add_patch(patches.Rectangle((-0.1, -0.1), 0.6, 0.5, edgecolor='grey',
136 | facecolor='lightgrey', lw=1, fill=True,))
137 | ax.add_patch(patches.Polygon([(0.7, 0.5), (1.1, 1.1), (1.1, -0.1)],
138 | edgecolor='grey', facecolor='lightgrey', lw=1, fill=True,))
139 |
140 | # Text infomation
141 | ax.text(
142 | 0.7, 0.9,
143 | 'Agent 1',
144 | fontdict=text_font,
145 | color='black',
146 | verticalalignment='center',
147 | horizontalalignment='center'
148 | )
149 | ax.text(
150 | 0.7, 0.1,
151 | 'Agent 2',
152 | fontdict=text_font,
153 | color='black',
154 | verticalalignment='center',
155 | horizontalalignment='center'
156 | )
157 |
158 | # Legend
159 | ax.legend(loc='lower left', prop=legend_font)
160 |
161 | # Axis range
162 | ax.set_xlim(0, 1)
163 | ax.set_ylim(0, 1)
164 |
165 | # Label and title
166 | ax.get_xaxis().set_visible(False)
167 | ax.get_yaxis().set_visible(False)
168 | ax.set_title('Single Scatter Plot 3', fontdict=title_font)
169 |
170 | plt.tight_layout()
171 | plt.savefig('../fig/single-scatter-3.jpg', dpi=300)
172 |
173 |
189 |
80 | # Packages
81 | import numpy as np
82 | import matplotlib.pyplot as plt
83 | import matplotlib.patches as patches
84 | from matplotlib import cm
85 |
86 | # Use LaTeX font
87 | plt.rcParams.update({'text.usetex': True})
88 |
89 | # Figure font config
90 | label_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
91 | title_font = {'fontfamily': 'Arial Black', 'fontsize': 16}
92 | legend_font = {'family': 'Palatino Linotype', 'size': 10}
93 | text_font = {'family': 'Palatino Linotype', 'fontsize': 12}
94 |
95 | # Load data
96 | value = np.load('../data/single-scatter-4-value.npy')
97 | x = np.linspace(0, 256, 18, endpoint=True)
98 | y = np.linspace(0, 256, 18, endpoint=True)
99 |
100 | # Plot
101 | fig, ax = plt.subplots(1, figsize=(3, 3))
102 |
103 | # Plot background value
104 | ax.matshow(value, cmap=cm.RdGy, alpha=0.8)
105 |
106 | # Collocation Point
107 | for i in x:
108 | for j in y:
109 | ax.scatter(i, j, color='black', marker='.', s=5)
110 |
111 | # Mesh
112 | for i in range(17):
113 | for j in range(17):
114 | ax.plot([x[i], x[i+1]], [y[j], y[j]], color='black', linewidth=0.5)
115 | ax.plot([x[i], x[i]], [x[j], y[j+1]], color='black', linewidth=0.5)
116 |
117 | # Axis range
118 | ax.set_xlim(0, 256)
119 | ax.set_ylim(0, 256)
120 | ax.invert_yaxis()
121 |
122 | # Label and title
123 | ax.get_xaxis().set_visible(False)
124 | ax.get_yaxis().set_visible(False)
125 | ax.set_title('Single Scatter Plot 4', fontdict=title_font)
126 |
127 | plt.tight_layout()
128 | plt.savefig('../fig/single-scatter-4.jpg', dpi=300)
129 |
130 |
146 |
80 | # Packages
81 | import cv2 as cv
82 | import numpy as np
83 | import matplotlib.pyplot as plt
84 | import matplotlib.patches as patches
85 | from matplotlib import cm
86 |
87 | # Use LaTeX font
88 | plt.rcParams.update({'text.usetex': True})
89 |
90 | # Figure font config
91 | label_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
92 | title_font = {'fontfamily': 'Arial Black', 'fontsize': 16}
93 | legend_font = {'family': 'Palatino Linotype', 'size': 10}
94 | text_font = {'family': 'Palatino Linotype', 'fontsize': 12}
95 |
96 | # Load data
97 | # Note: shape = [num_step, num_agent, position]
98 | # last agent is the basketball
99 | hist = np.load('../data/single-scatter-5-hist.npy')
100 | pred = np.load('../data/single-scatter-5-pred.npy')
101 |
102 | # Scale the data
103 | hist[..., 0] = hist[..., 0] * 15
104 | hist[..., 1] = hist[..., 1] * 8
105 | pred[..., 0] = pred[..., 0] * 15
106 | pred[..., 1] = pred[..., 1] * 8
107 |
108 | # Plot
109 | fig, ax = plt.subplots(1, figsize=(5, 5))
110 |
111 | # Plot the beckground court
112 | img = cv.imread('../fig/utils/court.png')
113 | img = cv.cvtColor(img, cv.COLOR_BGR2RGB)
114 | ax.imshow(img, extent=[0, 15, 0, 8], alpha=0.6)
115 |
116 | # Scatter history trajectory
117 | ax.plot(hist[:, :5, 0], hist[:, :5, 1], label='History Team 1', color=cm.Set2(3),
118 | marker='o', lw=2, markersize=5, alpha=0.7)
119 | ax.plot(hist[:, 5:-1, 0], hist[:, 5:-1, 1], label='History Team 2', color=cm.Set2(2),
120 | marker='o', lw=2, markersize=5, alpha=0.7)
121 |
122 | # Scatter future trajectory
123 | ax.plot(pred[:, :5, 0], pred[:, :5, 1], label='Future Team 1', color=cm.Set2(1),
124 | marker='o', lw=2, markersize=5, alpha=0.7)
125 | ax.plot(pred[:, 5:-1, 0], pred[:, 5:-1, 1], label='Future Team 2', color=cm.Set2(0),
126 | marker='o', lw=2, markersize=5, alpha=0.7)
127 |
128 | # Scatter the basketball
129 | ax.plot(hist[:, -1, 0], hist[:, -1, 1], label='Basketball', color=cm.Set1(0),
130 | marker='^', lw=2, markersize=5, alpha=0.7)
131 | ax.plot(pred[:, -1, 0], pred[:, -1, 1], color=cm.Set1(0),
132 | marker='^', lw=2, markersize=5, alpha=0.7)
133 |
134 | # Connect history and future
135 | ax.plot([hist[0, :5, 0], pred[-1, :5, 0]], [hist[0, :5, 1], pred[-1, :5, 1]],
136 | color=cm.Set2(1), lw=2, ls='-', alpha=0.7)
137 | ax.plot([hist[0, 5:-1, 0], pred[-1, 5:-1, 0]], [hist[0, 5:-1, 1], pred[-1, 5:-1, 1]],
138 | color=cm.Set2(0), lw=2, ls='-', alpha=0.7)
139 | ax.plot([hist[0, -1, 0], pred[-1, -1, 0]], [hist[0, -1, 1], pred[-1, -1, 1]],
140 | color=cm.Set1(0), lw=2, ls='-', alpha=0.7)
141 |
142 | # Label and title
143 | ax.get_xaxis().set_visible(False)
144 | ax.get_yaxis().set_visible(False)
145 | ax.set_title('Single Scatter Plot 5', fontdict=title_font)
146 |
147 | # Legend
148 | handles, labels = ax.get_legend_handles_labels()
149 | labels = dict(zip(labels, handles))
150 | fig.legend(labels.values(), labels.keys(), loc='lower center', ncol=3, bbox_to_anchor=(0.5, 0.12), prop=legend_font)
151 |
152 | plt.tight_layout()
153 | plt.savefig('../fig/single-scatter-5.jpg', dpi=300)
154 |
155 |
171 | 72 | [TBD] Some posts about the prefabs. We will update this page soon. 73 |
74 |