11{
2- "nbformat" : 4 ,
3- "nbformat_minor" : 5 ,
4- "metadata" : {
5- "kernelspec" : {
6- "display_name" : " Python 3" ,
7- "language" : " python" ,
8- "name" : " python3"
9- },
10- "language_info" : {
11- "name" : " python" ,
12- "version" : " 3.12.0"
13- }
14- },
152 "cells" : [
163 {
174 "cell_type" : " markdown" ,
5643 "execution_count" : null ,
5744 "metadata" : {},
5845 "outputs" : [],
59- "source" : " from ggplotly import *\n import pandas as pd"
46+ "source" : [
47+ " from ggplotly import *\n " ,
48+ " import pandas as pd\n " ,
49+ " import numpy as np"
50+ ]
6051 },
6152 {
6253 "cell_type" : " markdown" ,
7061 "execution_count" : null ,
7162 "metadata" : {},
7263 "outputs" : [],
73- "source" : " # Create some data\n df = pd.DataFrame({\n 'x': [1, 2, 3, 4, 5],\n 'y': [2, 4, 3, 5, 4]\n })\n\n # Create a scatter plot\n (ggplot(df, aes(x='x', y='y')) + geom_point())"
64+ "source" : [
65+ " # Create some data\n " ,
66+ " df = pd.DataFrame({\n " ,
67+ " 'x': [1, 2, 3, 4, 5],\n " ,
68+ " 'y': [2, 4, 3, 5, 4]\n " ,
69+ " })\n " ,
70+ " \n " ,
71+ " # Create a scatter plot\n " ,
72+ " ggplot(df, aes(x='x', y='y')) + geom_point()"
73+ ]
7474 },
7575 {
7676 "cell_type" : " markdown" ,
9191 "execution_count" : null ,
9292 "metadata" : {},
9393 "outputs" : [],
94- "source" : " (\n ggplot(df, aes(x='x', y='y', color='category')) # Data + aesthetics\n + geom_point(size=3) # Geom\n + scale_color_brewer(palette='Set1') # Scale\n + theme_minimal() # Theme\n + labs(title='My Plot', x='X Axis', y='Y Axis') # Labels\n )"
94+ "source" : [
95+ " # More complete sample data\n " ,
96+ " np.random.seed(42)\n " ,
97+ " df = pd.DataFrame({\n " ,
98+ " 'x': np.random.randn(50),\n " ,
99+ " 'y': np.random.randn(50),\n " ,
100+ " 'category': np.random.choice(['A', 'B', 'C'], 50),\n " ,
101+ " 'values': np.random.rand(50) * 10\n " ,
102+ " })\n " ,
103+ " \n " ,
104+ " (\n " ,
105+ " ggplot(df, aes(x='x', y='y', color='category')) # Data + aesthetics\n " ,
106+ " + geom_point(size=5) # Geom\n " ,
107+ " + scale_color_brewer(palette='Set1') # Scale\n " ,
108+ " + theme_minimal() # Theme\n " ,
109+ " + labs(title='My Plot', x='X Axis', y='Y Axis') # Labels\n " ,
110+ " )"
111+ ]
95112 },
96113 {
97114 "cell_type" : " markdown" ,
107124 "execution_count" : null ,
108125 "metadata" : {},
109126 "outputs" : [],
110- "source" : " ggplot(df, aes(x='x', y='y', color='category')) + geom_point()"
127+ "source" : [
128+ " ggplot(df, aes(x='x', y='y', color='category')) + geom_point()"
129+ ]
111130 },
112131 {
113132 "cell_type" : " markdown" ,
121140 "execution_count" : null ,
122141 "metadata" : {},
123142 "outputs" : [],
124- "source" : " ggplot(df, aes(x='x', y='y')) + geom_point() + geom_line()"
143+ "source" : [
144+ " ggplot(df, aes(x='x', y='y')) + geom_point() + geom_smooth()"
145+ ]
125146 },
126147 {
127148 "cell_type" : " markdown" ,
135156 "execution_count" : null ,
136157 "metadata" : {},
137158 "outputs" : [],
138- "source" : " ggplot(df, aes(x='x', y='y')) + geom_point() + facet_wrap('category')"
159+ "source" : [
160+ " ggplot(df, aes(x='x', y='y')) + geom_point() + facet_wrap('category')"
161+ ]
139162 },
140163 {
141164 "cell_type" : " markdown" ,
149172 "execution_count" : null ,
150173 "metadata" : {},
151174 "outputs" : [],
152- "source" : " # Automatically use DataFrame index\n ggplot(df, aes(y='values')) + geom_line()\n\n # Or explicitly\n ggplot(df, aes(x='index', y='values')) + geom_line()\n\n # Works with Series too\n series = pd.Series([1, 2, 3], index=['a', 'b', 'c'])\n ggplot(series) + geom_point()"
175+ "source" : [
176+ " # Create time series data with index\n " ,
177+ " ts_df = pd.DataFrame({\n " ,
178+ " 'values': np.cumsum(np.random.randn(50)) + 50\n " ,
179+ " }, index=pd.date_range('2024-01-01', periods=50, freq='D'))\n " ,
180+ " \n " ,
181+ " # Automatically use DataFrame index\n " ,
182+ " ggplot(ts_df, aes(y='values')) + geom_line()"
183+ ]
153184 },
154185 {
155186 "cell_type" : " markdown" ,
156187 "metadata" : {},
157188 "source" : [
158- " ## Saving Plots"
189+ " ## Built-in Datasets\n " ,
190+ " \n " ,
191+ " ggplotly includes classic datasets for learning:"
159192 ]
160193 },
161194 {
162195 "cell_type" : " code" ,
163196 "execution_count" : null ,
164197 "metadata" : {},
165198 "outputs" : [],
166- "source" : " # Create plot\n p = ggplot(df, aes(x='x', y='y')) + geom_point()\n\n # Save as HTML (interactive)\n p.write_html('plot.html')\n\n # Save as image (requires kaleido)\n p.write_image('plot.png')\n\n # Or use ggsave\n ggsave(p, 'plot.png', width=800, height=600)"
167- },
168- {
169- "cell_type" : " markdown" ,
170- "metadata" : {},
171199 "source" : [
172- " ## Built-in Datasets \n " ,
200+ " from ggplotly import data \n " ,
173201 " \n " ,
174- " ggplotly includes classic datasets for learning:"
202+ " # See all available datasets\n " ,
203+ " data()"
175204 ]
176205 },
177206 {
178207 "cell_type" : " code" ,
179208 "execution_count" : null ,
180209 "metadata" : {},
181210 "outputs" : [],
182- "source" : " from ggplotly import data\n\n # Load a dataset\n mpg = data('mpg')\n diamonds = data('diamonds')\n iris = data('iris')\n\n # See all available datasets\n data()"
211+ "source" : [
212+ " # Load the iris dataset\n " ,
213+ " iris = data('iris')\n " ,
214+ " \n " ,
215+ " ggplot(iris, aes(x='sepal_length', y='sepal_width', color='species')) + geom_point()"
216+ ]
183217 },
184218 {
185219 "cell_type" : " markdown" ,
186220 "metadata" : {},
187221 "source" : [
222+ " ## Saving Plots\n " ,
223+ " \n " ,
224+ " ```python\n " ,
225+ " # Create plot\n " ,
226+ " p = ggplot(df, aes(x='x', y='y')) + geom_point()\n " ,
227+ " \n " ,
228+ " # Save as HTML (interactive)\n " ,
229+ " p.write_html('plot.html')\n " ,
230+ " \n " ,
231+ " # Save as image (requires kaleido)\n " ,
232+ " p.write_image('plot.png')\n " ,
233+ " \n " ,
234+ " # Or use ggsave\n " ,
235+ " ggsave(p, 'plot.png', width=800, height=600)\n " ,
236+ " ```\n " ,
237+ " \n " ,
188238 " ## Next Steps\n " ,
189239 " \n " ,
190240 " - [Aesthetics Guide](guide/aesthetics.ipynb) - Learn about mapping data to visual properties\n " ,
191241 " - [Geoms Reference](guide/geoms.ipynb) - Explore all available geometric objects\n " ,
192242 " - [Themes](guide/themes.ipynb) - Customize the look of your plots"
193243 ]
194244 }
195- ]
196- }
245+ ],
246+ "metadata" : {
247+ "kernelspec" : {
248+ "display_name" : " Python 3" ,
249+ "language" : " python" ,
250+ "name" : " python3"
251+ },
252+ "language_info" : {
253+ "name" : " python" ,
254+ "version" : " 3.9.0"
255+ }
256+ },
257+ "nbformat" : 4 ,
258+ "nbformat_minor" : 4
259+ }
0 commit comments