from plotly import tools # functions to help build plotly graphs
import plotly.plotly as py # module that communicates with plotly
from plotly.graph_objs import * # graph objects, subclasses of lists and dicts, that are used to describe plotly graphs
fig = tools.make_subplots(rows=2)
This is the format of your plot grid: [ (1,1) x1,y1 ] [ (2,1) x2,y2 ]
fig.append_trace(Scatter(x=[1,2,3], y=[2,1,2], name='top trace'), 1, 1)
fig.append_trace(Scatter(x=[1,2,3], y=[2,3,2], name='bottom trace'), 2, 1)
py.iplot(fig, filename='subplot example')
fig = tools.make_subplots(rows=2, shared_xaxes=True, print_grid=True)
This is the format of your plot grid: [ (1,1) x1,y1 ] [ (2,1) x1,y2 ]
fig.append_trace(Scatter(x=[1,2,3], y=[2,1,2]), 1, 1)
fig.append_trace(Scatter(x=[2,3,4], y=[2,3,2]), 2, 1)
py.iplot(fig, filename='shared xaxis')
nr = 6
nc = 6
fig = tools.make_subplots(rows=nr, cols=nc, print_grid=False)
for i in range(1, nr+1):
for j in range(1, nc+1):
fig.append_trace(Scatter(x=[1], y=[1],
text=['({}, {})'.format(i,j)],
mode='markers+text',
textposition='top'), row=i, col=j)
fig['layout']['showlegend'] = False
py.iplot(fig, filename='6x6')
nr = 6
nc = 6
fig = tools.make_subplots(rows=nr, cols=nc, print_grid=False,
shared_xaxes=True, shared_yaxes=True)
for i in range(1, nr+1):
for j in range(1, nc+1):
fig.append_trace(Scatter(x=[1], y=[1],
text=['({}, {})'.format(i,j)],
mode='markers+text',
textposition='top'), row=i, col=j)
fig['layout']['showlegend'] = False
py.iplot(fig, filename='6x6 shared')
fig = tools.make_subplots(insets=[{'cell': (1,1), 'l': 0.7, 'b': 0.7}],
print_grid=True)
This is the format of your plot grid: [ (1,1) x1,y1 ] With insets: [ x2,y2 ] over [ (1,1) x1,y1 ]
fig.append_trace(Scatter(x=[1,2,3], y=[2,1,2]), 1, 1)
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
py.iplot(fig, filename='inset example')
fig = tools.make_subplots(rows=2, cols=2,
specs=[[{}, {}],
[{'colspan': 2}, None]],
print_grid=True)
This is the format of your plot grid: [ (1,1) x1,y1 ] [ (1,2) x2,y2 ] [ (2,1) x3,y3 - ]
fig.append_trace(Scatter(x=[1,2,3], y=[2,1,2]), row=1, col=1)
fig.append_trace(Scatter(x=[1,2,3], y=[2,1,2]), row=1, col=2)
fig.append_trace(Scatter(x=[1,2,3], y=[2,1,2]), row=2, col=1)
py.iplot(fig, filename='irregular spacing')
fig = tools.make_subplots(rows=5, cols=2,
specs=[[{}, {'rowspan': 2}],
[{}, None],
[{'rowspan': 2, 'colspan': 2}, None],
[None, None],
[{}, {}]],
print_grid=True)
This is the format of your plot grid: [ (1,1) x1,y1 ] [ (1,2) x2,y2 ] [ (2,1) x3,y3 ] | [ (3,1) x4,y4 - ] | | [ (5,1) x5,y5 ] [ (5,2) x6,y6 ]
fig.append_trace(Scatter(x=[1,2],y=[1,4],name='(1,1)'), 1, 1)
fig.append_trace(Scatter(x=[1,2],y=[1,4],name='(2,1)'), 2, 1)
fig.append_trace(Scatter(x=[1,2],y=[1,4],name='(3,1)'), 3, 1)
fig.append_trace(Scatter(x=[1,2],y=[1,4],name='(5,1)'), 5, 1)
fig.append_trace(Scatter(x=[1,2],y=[1,4],name='(1,2)'), 1, 2)
fig.append_trace(Scatter(x=[1,2],y=[1,4],name='(5,2)'), 5, 2)
py.iplot(fig, filename='subplot unique arrangement')
tools.make_subplots
generates Figure
objects for you.
Need some help? Call help
help(tools.make_subplots)
Help on function make_subplots in module plotly.tools: make_subplots(rows=1, cols=1, shared_xaxes=False, shared_yaxes=False, start_cell='top-left', print_grid=True, **kwargs) Return an instance of plotly.graph_objs.Figure with the subplots domain set in 'layout'. Example 1: # stack two subplots vertically fig = tools.make_subplots(rows=2) This is the format of your plot grid: [ (1,1) x1,y1 ] [ (2,1) x2,y2 ] fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2])] fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')] # or see Figure.append_trace Example 2: # subplots with shared x axes fig = tools.make_subplots(rows=2, shared_xaxes=True) This is the format of your plot grid: [ (1,1) x1,y1 ] [ (2,1) x1,y2 ] fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2])] fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], yaxis='y2')] Example 3: # irregular subplot layout (more examples below under 'specs') fig = tools.make_subplots(rows=2, cols=2, specs=[[{}, {}], [{'colspan': 2}, None]]) This is the format of your plot grid! [ (1,1) x1,y1 ] [ (1,2) x2,y2 ] [ (2,1) x3,y3 - ] fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2])] fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')] fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x3', yaxis='y3')] Example 4: # insets fig = tools.make_subplots(insets=[{'cell': (1,1), 'l': 0.7, 'b': 0.3}]) This is the format of your plot grid! [ (1,1) x1,y1 ] With insets: [ x2,y2 ] over [ (1,1) x1,y1 ] fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2])] fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')] Keywords arguments with constant defaults: rows (kwarg, int greater than 0, default=1): Number of rows in the subplot grid. cols (kwarg, int greater than 0, default=1): Number of columns in the subplot grid. shared_xaxes (kwarg, boolean or list, default=False) Assign shared x axes. If True, subplots in the same grid column have one common shared x-axis at the bottom of the gird. To assign shared x axes per subplot grid cell (see 'specs'), send list (or list of lists, one list per shared x axis) of cell index tuples. shared_yaxes (kwarg, boolean or list, default=False) Assign shared y axes. If True, subplots in the same grid row have one common shared y-axis on the left-hand side of the gird. To assign shared y axes per subplot grid cell (see 'specs'), send list (or list of lists, one list per shared y axis) of cell index tuples. start_cell (kwarg, 'bottom-left' or 'top-left', default='top-left') Choose the starting cell in the subplot grid used to set the domains of the subplots. print_grid (kwarg, boolean, default=True): If True, prints a tab-delimited string representation of your plot grid. Keyword arguments with variable defaults: horizontal_spacing (kwarg, float in [0,1], default=0.2 / cols): Space between subplot columns. Applies to all columns (use 'specs' subplot-dependents spacing) vertical_spacing (kwarg, float in [0,1], default=0.3 / rows): Space between subplot rows. Applies to all rows (use 'specs' subplot-dependents spacing) specs (kwarg, list of lists of dictionaries): Subplot specifications. ex1: specs=[[{}, {}], [{'colspan': 2}, None]] ex2: specs=[[{'rowspan': 2}, {}], [None, {}]] - Indices of the outer list correspond to subplot grid rows starting from the bottom. The number of rows in 'specs' must be equal to 'rows'. - Indices of the inner lists correspond to subplot grid columns starting from the left. The number of columns in 'specs' must be equal to 'cols'. - Each item in the 'specs' list corresponds to one subplot in a subplot grid. (N.B. The subplot grid has exactly 'rows' times 'cols' cells.) - Use None for blank a subplot cell (or to move pass a col/row span). - Note that specs[0][0] has the specs of the 'start_cell' subplot. - Each item in 'specs' is a dictionary. The available keys are: * is_3d (boolean, default=False): flag for 3d scenes * colspan (int, default=1): number of subplot columns for this subplot to span. * rowspan (int, default=1): number of subplot rows for this subplot to span. * l (float, default=0.0): padding left of cell * r (float, default=0.0): padding right of cell * t (float, default=0.0): padding right of cell * b (float, default=0.0): padding bottom of cell - Use 'horizontal_spacing' and 'vertical_spacing' to adjust the spacing in between the subplots. insets (kwarg, list of dictionaries): Inset specifications. - Each item in 'insets' is a dictionary. The available keys are: * cell (tuple, default=(1,1)): (row, col) index of the subplot cell to overlay inset axes onto. * is_3d (boolean, default=False): flag for 3d scenes * l (float, default=0.0): padding left of inset in fraction of cell width * w (float or 'to_end', default='to_end') inset width in fraction of cell width ('to_end': to cell right edge) * b (float, default=0.0): padding bottom of inset in fraction of cell height * h (float or 'to_end', default='to_end') inset height in fraction of cell height ('to_end': to cell top edge)
fig = tools.make_subplots(rows=2)
This is the format of your plot grid: [ (1,1) x1,y1 ] [ (2,1) x2,y2 ]
fig
is a subclass of a dict
print fig
{'data': [], 'layout': {'yaxis1': {'domain': [0.575, 1.0], 'anchor': 'x1'}, 'yaxis2': {'domain': [0.0, 0.425], 'anchor': 'x2'}, 'xaxis2': {'domain': [0.0, 1.0], 'anchor': 'y2'}, 'xaxis1': {'domain': [0.0, 1.0], 'anchor': 'y1'}}}
to.string()
pretty prints the object
print fig.to_string()
Figure( data=Data(), layout=Layout( xaxis1=XAxis( domain=[0.0, 1.0], anchor='y1' ), xaxis2=XAxis( domain=[0.0, 1.0], anchor='y2' ), yaxis1=YAxis( domain=[0.575, 1.0], anchor='x1' ), yaxis2=YAxis( domain=[0.0, 0.425], anchor='x2' ) ) )
fig
subclasses a dict
, so access members just like you would in a dict
fig['layout']
{'xaxis1': {'anchor': 'y1', 'domain': [0.0, 1.0]}, 'xaxis2': {'anchor': 'y2', 'domain': [0.0, 1.0]}, 'yaxis1': {'anchor': 'x1', 'domain': [0.575, 1.0]}, 'yaxis2': {'anchor': 'x2', 'domain': [0.0, 0.425]}}
it's a bit different than a straight dictionary because only certain keys are allowed.
each key and value describes something about a plotly graph, so it's pretty strict.
for example, you can't initialize a Figure
with an invalid key. we'll throw an exception.
import traceback
try:
Figure(nonsense=3)
except:
print traceback.format_exc()
Traceback (most recent call last): File "<ipython-input-21-b18e717789cb>", line 3, in <module> Figure(nonsense=3) File "/usr/local/lib/python2.7/dist-packages/plotly/graph_objs/graph_objs.py", line 920, in __init__ super(Figure, self).__init__(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/plotly/graph_objs/graph_objs.py", line 312, in __init__ self.validate() File "/usr/local/lib/python2.7/dist-packages/plotly/graph_objs/graph_objs.py", line 600, in validate notes=notes) PlotlyDictKeyError: Invalid key, 'nonsense', for class, 'Figure'. Run 'help(plotly.graph_objs.Figure)' for more information. Path To Error: ['nonsense'] Additional Notes: Couldn't find uses for key: 'nonsense'
so, which keys are accepted? call help
! also check out https://plot.ly/python/reference/
help(fig['layout'])
Help on Layout in module plotly.graph_objs.graph_objs object: class Layout(PlotlyDict) | A dictionary-like object containing specification of the layout of a plotly | figure. | | Online examples: | | https://plot.ly/python/figure-labels/ | https://plot.ly/python/axes/ | https://plot.ly/python/bar-charts/ | https://plot.ly/python/log-plot/ | | Parent key: | | layout | | Quick method reference: | | Layout.update(changes) | Layout.strip_style() | Layout.get_data() | Layout.to_graph_objs() | Layout.validate() | Layout.to_string() | Layout.force_clean() | | Valid keys: | | title [required=False] (value=a string): | The title of the figure. | | titlefont [required=False] (value=Font object | dictionary-like object): | Links a dictionary-like object describing the font settings of the | figure's title. | | For more, run `help(plotly.graph_objs.Font)` | | font [required=False] (value=Font object | dictionary-like object): | Links a dictionary-like object describing the global font settings | for this figure (e.g. all axis titles and labels). | | For more, run `help(plotly.graph_objs.Font)` | | showlegend [required=False] (value=a boolean: True | False): | Toggle whether or not the legend will be shown in this figure. | | autosize [required=False] (value=a boolean: True | False): | Toggle whether or not the dimensions of the figure are automatically | picked by Plotly. Plotly picks figure's dimensions as a function of | your machine's display resolution. Once 'autosize' is set to False, | the figure's dimensions can be set with 'width' and 'height'. | | width [required=False] (value=number: x > 0): | Sets the width in pixels of the figure you are generating. | | height [required=False] (value=number: x > 0): | Sets the height in pixels of the figure you are generating. | | xaxis [required=False] (value=XAxis object | dictionary-like object): | Links a dictionary-like object describing an x-axis (i.e. an | horizontal axis). The first XAxis object can be entered into | 'layout' by linking it to 'xaxis' OR 'xaxis1', both keys are | identical to Plotly. To create references other than x-axes, you | need to define them in 'layout' using keys 'xaxis2', 'xaxis3' and so | on. Note that in 3D plots, XAxis objects must be linked from a Scene | object. | | For more, run `help(plotly.graph_objs.XAxis)` | | yaxis [required=False] (value=YAxis object | dictionary-like object): | Links a dictionary-like object describing an y-axis (i.e. an | vertical axis). The first YAxis object can be entered into 'layout' | by linking it to 'yaxis' OR 'yaxis1', both keys are identical to | Plotly. To create references other than y-axes, you need to define | them in 'layout' using keys 'yaxis2', 'yaxis3' and so on. Note that | in 3D plots, YAxis objects must be linked from a Scene object. | | For more, run `help(plotly.graph_objs.YAxis)` | | legend [required=False] (value=Legend object | dictionary-like object): | Links a dictionary-like object containing the legend parameters for | this figure. | | For more, run `help(plotly.graph_objs.Legend)` | | annotations [required=False] (value=Annotations object | list-like | object of one or several dictionary-like object): | Links a list-like object that contains one or multiple annotation | dictionary-like objects. | | For more, run `help(plotly.graph_objs.Annotations)` | | margin [required=False] (value=Margin object | dictionary-like object): | Links a dictionary-like object containing the margin parameters for | this figure. | | For more, run `help(plotly.graph_objs.Margin)` | | paper_bgcolor [required=False] (value=a string describing color): | Sets the color of the figure's paper (i.e. area representing the | canvas of the figure). | | Examples: | 'green' | 'rgb(0, 255, 0)' | 'rgba(0, 255, 0, 0.3)' | | 'hsl(120,100%,50%)' | 'hsla(120,100%,50%,0.3)' | '#434F1D' | | plot_bgcolor [required=False] (value=a string describing color): | Sets the background color of the plot (i.e. the area laying inside | this figure's axes. | | Examples: | 'green' | 'rgb(0, 255, 0)' | 'rgba(0, 255, 0, 0.3)' | | 'hsl(120,100%,50%)' | 'hsla(120,100%,50%,0.3)' | '#434F1D' | | hovermode [required=False] (value='closest' | 'x' | 'y'): | Sets this figure's behavior when a user hovers over it. When set to | 'x', all data sharing the same 'x' coordinate will be shown on | screen with corresponding trace labels. When set to 'y' all data | sharing the same 'y' coordinates will be shown on the screen with | corresponding trace labels. When set to 'closest', information about | the data point closest to where the viewer is hovering will appear. | | dragmode [required=False] (value='zoom' | 'pan' | 'rotate' (in 3D | plots)): | Sets this figure's behavior when a user preforms a mouse 'drag' in | the plot area. When set to 'zoom', a portion of the plot will be | highlighted, when the viewer exits the drag, this highlighted | section will be zoomed in on. When set to 'pan', data in the plot | will move along with the viewers dragging motions. A user can always | depress the 'shift' key to access the whatever functionality has not | been set as the default. In 3D plots, the default drag mode is | 'rotate' which rotates the scene. | | separators [required=False] (value=a two-character string): | Sets the decimal (the first character) and thousands (the second | character) separators to be displayed on this figure's tick labels | and hover mode. This is meant for internationalization purposes. For | example, if 'separator' is set to ', ', then decimals are separated | by commas and thousands by spaces. One may have to set | 'exponentformat' to 'none' in the corresponding axis object(s) to | see the effects. | | barmode [required=False] (value='stack' | 'group' | 'overlay'): | For bar and histogram plots only. This sets how multiple bar objects | are plotted together. In other words, this defines how bars at the | same location appear on the plot. If set to 'stack' the bars are | stacked on top of one another. If set to 'group', the bars are | plotted next to one another, centered around the shared location. If | set to 'overlay', the bars are simply plotted over one another, you | may need to set the opacity to see this. | | bargap [required=False] (value=number: x in [0, 1)): | For bar and histogram plots only. Sets the gap between bars (or sets | of bars) at different locations. | | bargroupgap [required=False] (value=number: x in [0, 1)): | For bar and histogram plots only. Sets the gap between bars in the | same group. That is, when multiple bar objects are plotted and share | the same locations, this sets the distance between bars at each | location. | | boxmode [required=False] (value='overlay' | 'group'): | For box plots only. Sets how groups of box plots appear. If set to | 'overlay', a group of boxes will be plotted directly on top of one | another at their specified location. If set to 'group', the boxes | will be centered around their shared location, but they will not | overlap. | | boxgap [required=False] (value=number: x in [0, 1)): | For box plots only. Sets the gap between boxes at different | locations (i.e. x-labels). If there are multiple boxes at a single | x-label, then this sets the gap between these sets of boxes.For | example, if 0, then there is no gap between boxes. If 0.25, then | this gap occupies 25% of the available space and the box width (or | width of the set of boxes) occupies the remaining 75%. | | boxgroupgap [required=False] (value=number: x in [0, 1)): | For box plots only. Sets the gap between boxes in the same group, | where a group is the set of boxes with the same location (i.e. | x-label). For example, if 0, then there is no gap between boxes. If | 0.25, then this gap occupies 25% of the available space and the box | width occupies the remaining 75%. | | radialaxis [required=False] (value=RadialAxis object | dictionary-like | object): | Links a dictionary-like object describing the radial axis in a polar | plot. | | For more, run `help(plotly.graph_objs.RadialAxis)` | | angularaxis [required=False] (value=AngularAxis object | dictionary-like | object): | Links a dictionary-like object describing the angular axis in a | polar plot. | | For more, run `help(plotly.graph_objs.AngularAxis)` | | scene [required=False] (value=Scene object | dictionary-like object): | Links a dictionary-like object describing a scene in a 3D plot. The | first Scene object can be entered into 'layout' by linking it to | 'scene' OR 'scene1', both keys are identical to Plotly. Link | subsequent Scene objects using 'scene2', 'scene3', etc. | | For more, run `help(plotly.graph_objs.Scene)` | | direction [required=False] (value='clockwise' | 'counterclockwise'): | For polar plots only. Sets the direction corresponding to positive | angles. | | orientation [required=False] (value=number: x in [-360, 360]): | For polar plots only. Rotates the entire polar by the given angle. | | hidesources [required=False] (value=a boolean: True | False): | Toggle whether or not an annotation citing the data source is placed | at the bottom-right corner of the figure.This key has an effect only | on graphs that have been generated from forked graphs from plot.ly. | | Method resolution order: | Layout | PlotlyDict | __builtin__.dict | __builtin__.object | | Methods defined here: | | __init__(self, *args, **kwargs) | | force_clean(self, caller=True) | Attempts to convert to graph_objs and call force_clean() on values. | | Calling force_clean() on a Layout will ensure that the object is | valid and may be sent to plotly. This process will also remove any | entries that end up with a length == 0. | | Careful! This will delete any invalid entries *silently*. | | This method differs from the parent (PlotlyDict) method in that it | must check for an infinite number of possible axis keys, i.e. 'xaxis', | 'xaxis1', 'xaxis2', 'xaxis3', etc. Therefore, it cannot make a call | to super... | | to_graph_objs(self, caller=True) | Walk obj, convert dicts and lists to plotly graph objs. | | For each key in the object, if it corresponds to a special key that | should be associated with a graph object, the ordinary dict or list | will be reinitialized as a special PlotlyDict or PlotlyList of the | appropriate `kind`. | | to_string(self, level=0, indent=4, eol='\n', pretty=True, max_chars=80) | Returns a formatted string showing graph_obj constructors. | | Example: | | print(obj.to_string()) | | Keyword arguments: | level (default = 0) -- set number of indentations to start with | indent (default = 4) -- set indentation amount | eol (default = '\n') -- set end of line character(s) | pretty (default = True) -- curtail long list output with a '...' | max_chars (default = 80) -- set max characters per line | | ---------------------------------------------------------------------- | Methods inherited from PlotlyDict: | | __setitem__(self, key, value) | | get_data(self) | Returns the JSON for the plot with non-data elements stripped. | | get_ordered(self, caller=True) | | strip_style(self) | Strip style from the current representation. | | All PlotlyDicts and PlotlyLists are guaranteed to survive the | stripping process, though they made be left empty. This is allowable. | | Keys that will be stripped in this process are tagged with | `'type': 'style'` in graph_objs_meta.json. | | This process first attempts to convert nested collections from dicts | or lists to subclasses of PlotlyList/PlotlyDict. This process forces | a validation, which may throw exceptions. | | Then, each of these objects call `strip_style` on themselves and so | on, recursively until the entire structure has been validated and | stripped. | | update(self, dict1=None, **dict2) | Update current dict with dict1 and then dict2. | | This recursively updates the structure of the original dictionary-like | object with the new entries in the second and third objects. This | allows users to update with large, nested structures. | | Note, because the dict2 packs up all the keyword arguments, you can | specify the changes as a list of keyword agruments. | | Examples: | # update with dict | obj = Layout(title='my title', xaxis=XAxis(range=[0,1], domain=[0,1])) | update_dict = dict(title='new title', xaxis=dict(domain=[0,.8])) | obj.update(update_dict) | obj | {'title': 'new title', 'xaxis': {'range': [0,1], 'domain': [0,.8]}} | | # update with list of keyword arguments | obj = Layout(title='my title', xaxis=XAxis(range=[0,1], domain=[0,1])) | obj.update(title='new title', xaxis=dict(domain=[0,.8])) | obj | {'title': 'new title', 'xaxis': {'range': [0,1], 'domain': [0,.8]}} | | This 'fully' supports duck-typing in that the call signature is | identical, however this differs slightly from the normal update | method provided by Python's dictionaries. | | validate(self, caller=True) | Recursively check the validity of the keys in a PlotlyDict. | | The valid keys constitute the entries in each object | dictionary in graph_objs_meta.json | | The validation process first requires that all nested collections be | converted to the appropriate subclass of PlotlyDict/PlotlyList. Then, | each of these objects call `validate` and so on, recursively, | until the entire object has been validated. | | ---------------------------------------------------------------------- | Data descriptors inherited from PlotlyDict: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Methods inherited from __builtin__.dict: | | __cmp__(...) | x.__cmp__(y) <==> cmp(x,y) | | __contains__(...) | D.__contains__(k) -> True if D has a key k, else False | | __delitem__(...) | x.__delitem__(y) <==> del x[y] | | __eq__(...) | x.__eq__(y) <==> x==y | | __ge__(...) | x.__ge__(y) <==> x>=y | | __getattribute__(...) | x.__getattribute__('name') <==> x.name | | __getitem__(...) | x.__getitem__(y) <==> x[y] | | __gt__(...) | x.__gt__(y) <==> x>y | | __iter__(...) | x.__iter__() <==> iter(x) | | __le__(...) | x.__le__(y) <==> x<=y | | __len__(...) | x.__len__() <==> len(x) | | __lt__(...) | x.__lt__(y) <==> x<y | | __ne__(...) | x.__ne__(y) <==> x!=y | | __repr__(...) | x.__repr__() <==> repr(x) | | __sizeof__(...) | D.__sizeof__() -> size of D in memory, in bytes | | clear(...) | D.clear() -> None. Remove all items from D. | | copy(...) | D.copy() -> a shallow copy of D | | fromkeys(...) | dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v. | v defaults to None. | | get(...) | D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None. | | has_key(...) | D.has_key(k) -> True if D has a key k, else False | | items(...) | D.items() -> list of D's (key, value) pairs, as 2-tuples | | iteritems(...) | D.iteritems() -> an iterator over the (key, value) items of D | | iterkeys(...) | D.iterkeys() -> an iterator over the keys of D | | itervalues(...) | D.itervalues() -> an iterator over the values of D | | keys(...) | D.keys() -> list of D's keys | | pop(...) | D.pop(k[,d]) -> v, remove specified key and return the corresponding value. | If key is not found, d is returned if given, otherwise KeyError is raised | | popitem(...) | D.popitem() -> (k, v), remove and return some (key, value) pair as a | 2-tuple; but raise KeyError if D is empty. | | setdefault(...) | D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D | | values(...) | D.values() -> list of D's values | | viewitems(...) | D.viewitems() -> a set-like object providing a view on D's items | | viewkeys(...) | D.viewkeys() -> a set-like object providing a view on D's keys | | viewvalues(...) | D.viewvalues() -> an object providing a view on D's values | | ---------------------------------------------------------------------- | Data and other attributes inherited from __builtin__.dict: | | __hash__ = None | | __new__ = <built-in method __new__ of type object> | T.__new__(S, ...) -> a new object with type S, a subtype of T
fig['layout']['title'] = 'two subplots'
fig.append_trace
is a helper function for binding trace objects to axes. need some help? call help
!
help(fig.append_trace)
Help on method append_trace in module plotly.graph_objs.graph_objs: append_trace(self, trace, row, col) method of plotly.graph_objs.graph_objs.Figure instance Helper function to add a data traces to your figure that is bound to axes at the row, col index. The row, col index is generated from figures created with plotly.tools.make_subplots and can be viewed with Figure.print_grid. Example: # stack two subplots vertically fig = tools.make_subplots(rows=2) This is the format of your plot grid: [ (1,1) x1,y1 ] [ (2,1) x2,y2 ] fig.append_trace(Scatter(x=[1,2,3], y=[2,1,2]), 1, 1) fig.append_trace(Scatter(x=[1,2,3], y=[2,1,2]), 2, 1) Arguments: trace (plotly trace object): The data trace to be bound. row (int): Subplot row index on the subplot grid (see Figure.print_grid) col (int): Subplot column index on the subplot grid (see Figure.print_grid)
fig.append_trace(Scatter(x=[1,2,3], y=[2,1,2], name='top trace'), row=1, col=1) # (row, col) match with the subplot arrangment that was printed out
fig.append_trace(Scatter(x=[1,2,3], y=[2,1,2], name='bottom trace'), row=2, col=1)
print fig
{'data': [{'name': 'top trace', 'yaxis': 'y1', 'xaxis': 'x1', 'y': [2, 1, 2], 'x': [1, 2, 3], 'type': u'scatter'}, {'name': 'bottom trace', 'yaxis': 'y2', 'xaxis': 'x2', 'y': [2, 1, 2], 'x': [1, 2, 3], 'type': u'scatter'}], 'layout': {'yaxis1': {'domain': [0.575, 1.0], 'anchor': 'x1'}, 'yaxis2': {'domain': [0.0, 0.425], 'anchor': 'x2'}, 'xaxis2': {'domain': [0.0, 1.0], 'anchor': 'y2'}, 'xaxis1': {'domain': [0.0, 1.0], 'anchor': 'y1'}, 'title': 'two subplots'}}
print fig.to_string()
Figure( data=Data([ Scatter( x=[1, 2, 3], y=[2, 1, 2], name='top trace', xaxis='x1', yaxis='y1' ), Scatter( x=[1, 2, 3], y=[2, 1, 2], name='bottom trace', xaxis='x2', yaxis='y2' ) ]), layout=Layout( title='two subplots', xaxis1=XAxis( domain=[0.0, 1.0], anchor='y1' ), xaxis2=XAxis( domain=[0.0, 1.0], anchor='y2' ), yaxis1=YAxis( domain=[0.575, 1.0], anchor='x1' ), yaxis2=YAxis( domain=[0.0, 0.425], anchor='x2' ) ) )
see the two Scatter traces in fig['data']
above? we just inserted those!
to view this graph, send it over to your plotly account
py.iplot(fig, filename='subplot example')
now take a look at the examples above. in each case, we're just specifying a subplot arrangment and appending traces to the subplot coordinates that were printed
from IPython.display import display, HTML
import urllib2
url = 'https://raw.githubusercontent.com/plotly/python-user-guide/master/custom.css'
display(HTML(urllib2.urlopen(url).read()))