import plotly
from plotly.graph_objs import Scatter, Layout
import plotly.graph_objs as go
marks_data = [go.Bar(x=production.index, y=production["2000-01"])]
plotly.offline.plot({ 'data': marks_data,
'layout': {
'title': 'Marks Distribution',
'xaxis': {
'title': 'Items'},
'yaxis': {
'title': 'Year '}
}})
India Production Data β Advanced Plotly VisualizationsΒΆ
This project creates a comprehensive set of interactive Plotly visualizations for Indiaβs electronic production data. It covers bar charts for single-category analysis, multi-trace scatter plots comparing 10+ production categories simultaneously (mobile handsets, software, hardware, consumer electronics), interactive data tables with plotly.figure_factory, 2D histogram contour plots, Cufflinks integration for one-line plotting, and Seaborn statistical visualizations (distribution and box plots).
Why this matters: Real-world data presentations often require multiple visualization types tailored to different audiences and questions. This project demonstrates the full spectrum of Plotly capabilities β from simple bar charts to advanced contour plots β showing how to choose the right chart type for each analytical question. The multi-trace scatter plot comparing all production sectors over time is particularly valuable for identifying which industries are growing fastest.
import pandas as pd
production = pd.read_csv("mobile.csv", index_col="Item")
production.head()
production.index
production["2000-01"]
production.head()
production[["2000-01","2014-15"]]
production.groupby("")
import plotly.plotly as py
import plotly.graph_objs as go
# Create random data with numpy
import numpy as np
N = 100
random_x = np.linspace(0, 1, N)
random_y0 = np.random.randn(N)+5
random_y1 = np.random.randn(N)
random_y2 = np.random.randn(N)-5
# Create traces
trace0 = go.Scatter(
x = random_x,
y = random_y0,
mode = 'markers',
name = 'markers'
)
trace1 = go.Scatter(
x = random_x,
y = random_y1,
mode = 'lines+markers',
name = 'lines+markers'
)
trace2 = go.Scatter(
x = random_x,
y = random_y2,
mode = 'lines',
name = 'lines'
)
data = [trace0, trace1, trace2]
plotly.offline.plot(data, filename='scatter-mode.html')
import plotly.plotly as py
import plotly.graph_objs as go
import plotly.figure_factory as FF
import numpy as np
import pandas as pd
df = pd.read_csv('mobile.csv')
sample_data_table = FF.create_table(df.head())
plotly.offline.plot(sample_data_table, filename='sample-data-table.html')
import plotly.tools as tls
tls.embed('https://plot.ly/~cufflinks/8')
from plotly.graph_objs import *
import numpy as np
x = np.random.randn(2000)
y = np.random.randn(2000)
plotly.offline.plot([Histogram2dContour(x=x, y=y, contours=Contours(coloring='heatmap')),
Scatter(x=x, y=y, mode='markers', marker=Marker(color='white', size=3, opacity=0.3))], show_link=False)
import cufflinks as cf
plotly.offline.plot(cf.datagen.lines().iplot(asFigure=True,
kind='scatter',xTitle='Dates',yTitle='Returns',title='Returns'))
import plotly.plotly as py
fig = py.get_figure('https://plot.ly/~jackp/8715', raw=True)
plotly.offline.plot(fig)
mobile = pd.read_csv("mobile.csv", index_col="Item")
mobile.head()
mobile_t = mobile.transpose()
mobile_t.head()
mobile_t["Mobile Handsets"].nunique()
import plotly
from plotly.graph_objs import Scatter, Layout
import plotly.graph_objs as go
mobile_data = [go.Bar(x=mobile_t.index, y=mobile_t["Mobile Handsets"])]
plotly.offline.plot({ 'data': mobile_data,
'layout': {
'title': 'Mobile Production India',
'xaxis': {
'title': 'Year'},
'yaxis': {
'title': 'Sales '}
}})
output = None
production = pd.read_csv("production.csv", index_col="Item")
production_t = production.transpose()
production_t.head()
df = df.drop('2001-02', 0)
production_t = df
df
import plotly.plotly as py
import plotly.graph_objs as go
# Create random data with numpy
import numpy as np
N = 100
random_x = np.linspace(0, 1, N)
random_y0 = np.random.randn(N)+5
random_y1 = np.random.randn(N)
random_y2 = np.random.randn(N)-5
# Create traces
trace0 = go.Scatter(
x = random_x,
y = random_y0,
mode = 'lines',
name = 'lines'
)
trace1 = go.Scatter(
x = random_x,
y = random_y1,
mode = 'lines+markers',
name = 'lines+markers'
)
trace2 = go.Scatter(
x = random_x,
y = random_y2,
mode = 'markers',
name = 'markers'
)
data = [trace0, trace1, trace2]
plotly.offline.plot(data, filename='line-mode')
import plotly.plotly as py
import plotly.graph_objs as go
# Create random data with numpy
import numpy as np
# Create traces
trace0 = go.Scatter(
x=production_t.index, y=production_t["Mobile Handsets"],
mode = 'lines',
name = 'Mobile Handsets'
)
trace1 = go.Scatter(
x=production_t.index, y=production_t["Sub-Total (Software)"],
mode = 'lines+markers',
name = 'Sub-Total (Software)'
)
trace2 = go.Scatter(
x=production_t.index, y=production_t["Software for Exports"],
mode = 'markers',
name = 'Software for Exports'
)
trace3 = go.Scatter(
x=production_t.index, y=production_t["Consumer Electronics"],
mode = 'lines',
name = 'Consumer Electronics'
)
trace4 = go.Scatter(
x=production_t.index, y=production_t["Industrial Electronics"],
mode = 'lines+markers',
name = 'Industrial Electronics'
)
trace5 = go.Scatter(
x=production_t.index, y=production_t["Computer Hardware"],
mode = 'markers',
name = 'Computer Hardware'
)
trace6 = go.Scatter(
x=production_t.index, y=production_t["Strategic Electronics"],
mode = 'lines+markers',
name = 'Strategic Electronics'
)
trace7 = go.Scatter(
x=production_t.index, y=production_t["Electronics Components"],
mode = 'markers',
name = 'Electronics Components'
)
trace9 = go.Scatter(
x=production_t.index, y=production_t["Sub-Total (Hardware)"],
mode = 'lines+markers',
name = 'Sub-Total (Hardware)'
)
trace10 = go.Scatter(
x=production_t.index, y=production_t["Domestic Software"],
mode = 'markers',
name = 'Domestic Software'
)
data = [trace0, trace1, trace2,trace3, trace4, trace5,trace6, trace7,trace9,trace10]
plotly.offline.plot(data, filename='line-mode')
import plotly
from plotly.graph_objs import Scatter, Layout
import plotly.graph_objs as go
mobile_data = [go.Bar(x=df.index, y=df["Mobile Handsets"])]
print(mobile_data)
plotly.offline.plot({ 'data': mobile_data,
'layout': {
'title': 'Mobile Production India',
'xaxis': {
'title': 'Year'},
'yaxis': {
'title': 'Sales '}
}})
df["Mobile Handsets"]
import seaborn as sns
sns.set(color_codes=True)
%matplotlib inline
sns.distplot(mobile_t)
mobile_t
sns.set_style("whitegrid")
sns.boxplot(data=mobile_t);