#!/usr/bin/env python
# coding: utf-8
# #### New to Plotly?
# Plotly's Python library is free and open source! [Get started](https://plotly.com/python/getting-started/) by downloading the client and [reading the primer](https://plotly.com/python/getting-started/).
#
You can set up Plotly to work in [online](https://plotly.com/python/getting-started/#initialization-for-online-plotting) or [offline](https://plotly.com/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plotly.com/python/getting-started/#start-plotting-online).
#
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!
# #### Version Check
# Note: Subplots with multiple chart types (i.e. cartesian and 3D) are available in version 1.12.11+
# Run `pip install plotly --upgrade` to update your Plotly version
# In[1]:
import plotly
plotly.__version__
# #### Mixed Subplot
# In[2]:
import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd
# read in volcano database data
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/volcano_db.csv')
# frequency of Country
freq = df
freq = freq.Country.value_counts().reset_index().rename(columns={'index': 'x'})
# plot(1) top 10 countries by total volcanoes
locations = go.Bar(x=freq['x'][0:10],y=freq['Country'][0:10], marker=dict(color='#CF1020'))
# read in 3d volcano surface data
df_v = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/volcano.csv')
# plot(2) 3d surface of volcano
threed = go.Surface(z=df_v.values.tolist(), colorscale='Reds', showscale=False)
# plot(3) scattergeo map of volcano locations
trace3 = {
"geo": "geo3",
"lon": df['Longitude'],
"lat": df['Latitude'],
"hoverinfo": 'text',
"marker": {
"size": 4,
"opacity": 0.8,
"color": '#CF1020',
"colorscale": 'Viridis'
},
"mode": "markers",
"type": "scattergeo"
}
data = [locations, threed, trace3]
# control the subplot below using domain in 'geo', 'scene', and 'axis'
layout = {
"plot_bgcolor": 'black',
"paper_bgcolor": 'black',
"titlefont": {
"size": 20,
"family": "Raleway"
},
"font": {
"color": 'white'
},
"dragmode": "zoom",
"geo3": {
"domain": {
"x": [0, 0.55],
"y": [0, 0.9]
},
"lakecolor": "rgba(127,205,255,1)",
"oceancolor": "rgb(6,66,115)",
"landcolor": 'white',
"projection": {"type": "orthographic"},
"scope": "world",
"showlakes": True,
"showocean": True,
"showland": True,
"bgcolor": 'black'
},
"margin": {
"r": 10,
"t": 25,
"b": 40,
"l": 60
},
"scene": {"domain": {
"x": [0.5, 1],
"y": [0, 0.55]
},
"xaxis": {"gridcolor": 'white'},
"yaxis": {"gridcolor": 'white'},
"zaxis": {"gridcolor": 'white'}
},
"showlegend": False,
"title": "
Volcano Database",
"xaxis": {
"anchor": "y",
"domain": [0.6, 0.95]
},
"yaxis": {
"anchor": "x",
"domain": [0.65, 0.95],
"showgrid": False
}
}
annotations = { "text": "Source: NOAA",
"showarrow": False,
"xref": "paper",
"yref": "paper",
"x": 0,
"y": 0}
layout['annotations'] = [annotations]
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename = "Mixed Subplots Volcano")
# #### Reference
# See https://plotly.com/python/reference/ for more information and chart attribute options!
# In[3]:
from IPython.display import display, HTML
display(HTML(''))
display(HTML(''))
#!pip install git+https://github.com/plotly/publisher.git --upgrade
import publisher
publisher.publish(
'mixed-subplots.ipynb', 'python/mixed-subplots/', 'Mixed Subplots',
'How to make mixed subplots in Python with Plotly.',
title = 'Mixed Subplots | plotly',
name = 'Mixed Subplots',
has_thumbnail='true', thumbnail='thumbnail/mixed_subplot.JPG',
language='python', page_type='example_index',
display_as='multiple_axes', order=5,
ipynb= '~notebook_demo/132')
# In[ ]: