Python plotly.plotly.iplot() Examples
The following are 12
code examples of plotly.plotly.iplot().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
plotly.plotly
, or try the search function
.
Example #1
Source File: plotly.py From lddmm-ot with MIT License | 5 votes |
def _plot_option_logic(plot_options_from_call_signature): """ Given some plot_options as part of a plot call, decide on final options. Precedence: 1 - Start with DEFAULT_PLOT_OPTIONS 2 - Update each key with ~/.plotly/.config options (tls.get_config) 3 - Update each key with session plot options (set by py.sign_in) 4 - Update each key with plot, iplot call signature options """ default_plot_options = copy.deepcopy(DEFAULT_PLOT_OPTIONS) file_options = tools.get_config_file() session_options = get_session_plot_options() plot_options_from_call_signature = copy.deepcopy(plot_options_from_call_signature) # Validate options and fill in defaults w world_readable and sharing for option_set in [plot_options_from_call_signature, session_options, file_options]: utils.validate_world_readable_and_sharing_settings(option_set) utils.set_sharing_and_world_readable(option_set) # dynamic defaults if ('filename' in option_set and 'fileopt' not in option_set): option_set['fileopt'] = 'overwrite' user_plot_options = {} user_plot_options.update(default_plot_options) user_plot_options.update(file_options) user_plot_options.update(session_options) user_plot_options.update(plot_options_from_call_signature) user_plot_options = {k: v for k, v in user_plot_options.items() if k in default_plot_options} return user_plot_options
Example #2
Source File: plotly.py From lddmm-ot with MIT License | 5 votes |
def iplot_mpl(fig, resize=True, strip_style=False, update=None, **plot_options): """Replot a matplotlib figure with plotly in IPython. This function: 1. converts the mpl figure into JSON (run help(plolty.tools.mpl_to_plotly)) 2. makes a request to Plotly to save this figure in your account 3. displays the image in your IPython output cell Positional agruments: fig -- a figure object from matplotlib Keyword arguments: resize (default=True) -- allow plotly to choose the figure size strip_style (default=False) -- allow plotly to choose style options update (default=None) -- update the resulting figure with an 'update' dictionary-like object resembling a plotly 'Figure' object Additional keyword arguments: plot_options -- run help(plotly.plotly.iplot) """ fig = tools.mpl_to_plotly(fig, resize=resize, strip_style=strip_style) if update and isinstance(update, dict): fig.update(update) fig.validate() elif update is not None: raise exceptions.PlotlyGraphObjectError( "'update' must be dictionary-like and a valid plotly Figure " "object. Run 'help(plotly.graph_objs.Figure)' for more info." ) return iplot(fig, **plot_options)
Example #3
Source File: plotly.py From lddmm-ot with MIT License | 5 votes |
def ishow(cls, figure_or_data, format='png', width=None, height=None, scale=None): """Display a static image of the plot described by `figure_or_data` in an IPython Notebook. positional arguments: - figure_or_data: The figure dict-like or data list-like object that describes a plotly figure. Same argument used in `py.plot`, `py.iplot`, see https://plot.ly/python for examples - format: 'png', 'svg', 'jpeg', 'pdf' - width: output width - height: output height - scale: Increase the resolution of the image by `scale` amount Only valid for PNG and JPEG images. example: ``` import plotly.plotly as py fig = {'data': [{'x': [1, 2, 3], 'y': [3, 1, 5], 'type': 'bar'}]} py.image.ishow(fig, 'png', scale=3) """ if format == 'pdf': raise exceptions.PlotlyError( "Aw, snap! " "It's not currently possible to embed a pdf into " "an IPython notebook. You can save the pdf " "with the `image.save_as` or you can " "embed an png, jpeg, or svg.") img = cls.get(figure_or_data, format, width, height, scale) from IPython.display import display, Image, SVG if format == 'svg': display(SVG(img)) else: display(Image(img))
Example #4
Source File: plotly_stream.py From cloudbrain with GNU Affero General Public License v3.0 | 5 votes |
def setup_metric_streams(self, local_stream_ids, metric_name, num_channels): for i in range(num_channels): stream_id = local_stream_ids[i] self.stream_ids.append(stream_id) py_stream = py.Stream(stream_id) py_stream.open() self.py_streams.append(py_stream) go_stream = go.Stream(token=stream_id, maxpoints=self.max_points) self.go_streams.append(go_stream) traces = [] for i in range(num_channels): channel_name = "channel_%s" % i go_stream = self.go_streams[i] trace = go.Scatter( x=[], y=[], mode='splines', stream=go_stream, name=channel_name ) traces.append(trace) data = go.Data(traces) layout = go.Layout(title=metric_name) fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename=metric_name)
Example #5
Source File: learning_curve.py From dota2-predictor with MIT License | 4 votes |
def _plot_plotly(subset_sizes, data_list, mmr): """ Plots learning curve using plotly backend. Args: subset_sizes: list of dataset sizes on which the evaluation was done data_list: list of ROC AUC scores corresponding to subset_sizes mmr: what MMR the data is taken from """ if mmr: title = 'Learning curve plot for %d MMR' % mmr else: title = 'Learning curve plot' trace0 = go.Scatter( x=subset_sizes, y=data_list[0], name='Cross validation error' ) trace1 = go.Scatter( x=subset_sizes, y=data_list[1], name='Test error' ) data = go.Data([trace0, trace1]) layout = go.Layout( title=title, xaxis=dict( title='Dataset size (logspace)', type='log', autorange=True, titlefont=dict( family='Courier New, monospace', size=15, color='#7f7f7f' ) ), yaxis=dict( title='Error', titlefont=dict( family='Courier New, monospace', size=15, color='#7f7f7f' ) ) ) fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename='learning_curve_%dMMR' % mmr)
Example #6
Source File: hero_combinations.py From dota2-predictor with MIT License | 4 votes |
def plot_synergies(): synergies = np.loadtxt('pretrained/synergies_all.csv') for i in range(114): synergies[i, i] = 0.5 hero_dict = get_hero_dict() x_labels = [] for i in range(114): if i != 23: x_labels.append(hero_dict[i + 1]) synergies = np.delete(synergies, [23], 0) synergies = np.delete(synergies, [23], 1) trace = go.Heatmap(z=synergies, x=x_labels, y=x_labels, colorscale='Viridis') layout = go.Layout( title='Hero synergies', width=1000, height=1000, xaxis=dict(ticks='', nticks=114, tickfont=dict( size=8, color='black')), yaxis=dict(ticks='', nticks=114, tickfont=dict( size=8, color='black')) ) data = [trace] fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename='heatmap_synergies')
Example #7
Source File: hero_combinations.py From dota2-predictor with MIT License | 4 votes |
def plot_counters(): counters = np.loadtxt('pretrained/counters_all.csv') for i in range(114): counters[i, i] = 0.5 hero_dict = get_hero_dict() x_labels = [] for i in range(114): if i != 23: x_labels.append(hero_dict[i + 1]) counters = np.delete(counters, [23], 0) counters = np.delete(counters, [23], 1) trace = go.Heatmap(z=counters, x=x_labels, y=x_labels, colorscale='Viridis') layout = go.Layout( title='Hero counters (hero1 winrate against hero2)', width=1000, height=1000, xaxis=dict(ticks='', nticks=114, title='hero2', tickfont=dict( size=8, color='black')), yaxis=dict(ticks='', nticks=114, title='hero1', tickfont=dict( size=8, color='black')) ) data = [trace] fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename='heatmap_counters')
Example #8
Source File: dataset_stats.py From dota2-predictor with MIT License | 4 votes |
def winrate_statistics(dataset_df, mmr_info): x_data, y_data = dataset_df wins = np.zeros(114) games = np.zeros(114) winrate = np.zeros(114) for idx, game in enumerate(x_data): for i in range(228): if game[i] == 1: games[i % 114] += 1 if y_data[idx] == 1: if i < 114: wins[i] += 1 else: if i >= 114: wins[i - 114] += 1 winrate = wins / games winrate_dict = dict() hero_dict = get_hero_dict() for i in range(114): if i != 23: winrate_dict[hero_dict[i + 1]] = winrate[i] sorted_winrates = sorted(winrate_dict.items(), key=operator.itemgetter(1)) x_plot_data = [x[0] for x in sorted_winrates] y_plot_data = [x[1] for x in sorted_winrates] title = 'Hero winrates at ' + mmr_info + ' MMR' data = [go.Bar( y=x_plot_data, x=y_plot_data, orientation='h' )] layout = go.Layout( title=title, width=1000, height=1400, yaxis=dict(title='hero', ticks='', nticks=114, tickfont=dict( size=8, color='black') ), xaxis=dict(title='win rate', nticks=30, tickfont=dict( size=10, color='black') ) ) fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename='hero_winrates_' + mmr_info)
Example #9
Source File: dataset_stats.py From dota2-predictor with MIT License | 4 votes |
def pick_statistics(dataset_df, mmr_info): x_data, y_data = dataset_df wins = np.zeros(114) games = np.zeros(114) pick_rate = np.zeros(114) for idx, game in enumerate(x_data): for i in range(228): if game[i] == 1: games[i % 114] += 1 if y_data[idx] == 1: if i < 114: wins[i] += 1 else: if i >= 114: wins[i - 114] += 1 pick_rate = games / np.sum(games) pick_rate_dict = dict() hero_dict = get_hero_dict() for i in range(114): if i != 23: pick_rate_dict[hero_dict[i + 1]] = pick_rate[i] sorted_pickrates = sorted(pick_rate_dict.items(), key=operator.itemgetter(1)) x_plot_data = [x[0] for x in sorted_pickrates] y_plot_data = [x[1] for x in sorted_pickrates] title = 'Hero pick rates at ' + mmr_info + ' MMR' data = [go.Bar( y=x_plot_data, x=y_plot_data * 100, orientation='h' )] layout = go.Layout( title=title, width=1000, height=1400, yaxis=dict(title='hero', ticks='', nticks=114, tickfont=dict( size=8, color='black') ), xaxis=dict(title='pick rate', nticks=30, tickfont=dict( size=10, color='black') ) ) fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename='hero_pickrates_' + mmr_info)
Example #10
Source File: where_have_you_been.py From facebook-archive with MIT License | 4 votes |
def plot_on_map(locations): """ :params locations: The locations which have to be plotted Plots the point passed """ mapbox_access_token = 'pk.eyJ1IjoiYW5pbWVzaHNpbmdoIiwiYSI6ImNqcGM1MHpyeDJ0eHgzcXBoZDNrd3dyNnIifQ.N32_UbaPj_KSHkuIJfl33w' lat1 = list() long1 = list() lat_sum = 0 long_sum = 0 for i in locations: lat1.append(str(i[0])) long1.append(str(i[1])) lat_sum += i[0] long_sum += i[1] avg_lat = (lat_sum/len(locations)) avg_long = (long_sum/len(locations)) data = [ go.Scattermapbox( lat=lat1, lon=long1, mode='markers', marker=dict( size=14 ), text=['Locations'], ) ] layout = go.Layout( autosize=True, hovermode='closest', mapbox=dict( accesstoken=mapbox_access_token, bearing=0, center=dict( lat=avg_lat, lon=avg_long ), pitch=0, zoom=6 ), ) fig = dict(data=data, layout=layout) name = input('Enter your name: ') file = 'Location History-' + name print("View your plot in your browser at https://plot.ly/~animeshsingh38/ where it is named ",file) py.iplot(fig, filename=file)
Example #11
Source File: plotly.py From lddmm-ot with MIT License | 4 votes |
def iplot(figure_or_data, **plot_options): """Create a unique url for this plot in Plotly and open in IPython. plot_options keyword agruments: filename (string) -- the name that will be associated with this figure fileopt ('new' | 'overwrite' | 'extend' | 'append') - 'new': create a new, unique url for this plot - 'overwrite': overwrite the file associated with `filename` with this - 'extend': add additional numbers (data) to existing traces - 'append': add additional traces to existing data lists sharing ('public' | 'private' | 'secret') -- Toggle who can view this graph - 'public': Anyone can view this graph. It will appear in your profile and can appear in search engines. You do not need to be logged in to Plotly to view this chart. - 'private': Only you can view this plot. It will not appear in the Plotly feed, your profile, or search engines. You must be logged in to Plotly to view this graph. You can privately share this graph with other Plotly users in your online Plotly account and they will need to be logged in to view this plot. - 'secret': Anyone with this secret link can view this chart. It will not appear in the Plotly feed, your profile, or search engines. If it is embedded inside a webpage or an IPython notebook, anybody who is viewing that page will be able to view the graph. You do not need to be logged in to view this plot. world_readable (default=True) -- Deprecated: use "sharing". Make this figure private/public """ if 'auto_open' not in plot_options: plot_options['auto_open'] = False url = plot(figure_or_data, **plot_options) if isinstance(figure_or_data, dict): layout = figure_or_data.get('layout', {}) else: layout = {} embed_options = dict() embed_options['width'] = layout.get('width', '100%') embed_options['height'] = layout.get('height', 525) try: float(embed_options['width']) except (ValueError, TypeError): pass else: embed_options['width'] = str(embed_options['width']) + 'px' try: float(embed_options['height']) except (ValueError, TypeError): pass else: embed_options['height'] = str(embed_options['height']) + 'px' return tools.embed(url, **embed_options)
Example #12
Source File: plotly.py From lddmm-ot with MIT License | 4 votes |
def save_as(cls, figure_or_data, filename, format=None, width=None, height=None, scale=None): """Save a image of the plot described by `figure_or_data` locally as `filename`. Valid image formats are 'png', 'svg', 'jpeg', and 'pdf'. The format is taken as the extension of the filename or as the supplied format. positional arguments: - figure_or_data: The figure dict-like or data list-like object that describes a plotly figure. Same argument used in `py.plot`, `py.iplot`, see https://plot.ly/python for examples - filename: The filepath to save the image to - format: 'png', 'svg', 'jpeg', 'pdf' - width: output width - height: output height - scale: Increase the resolution of the image by `scale` amount Only valid for PNG and JPEG images. example: ``` import plotly.plotly as py fig = {'data': [{'x': [1, 2, 3], 'y': [3, 1, 5], 'type': 'bar'}]} py.image.save_as(fig, 'my_image.png', scale=3) ``` """ # todo: format shadows built-in name (base, ext) = os.path.splitext(filename) if not ext and not format: filename += '.png' elif ext and not format: format = ext[1:] elif not ext and format: filename += '.' + format img = cls.get(figure_or_data, format, width, height, scale) f = open(filename, 'wb') f.write(img) f.close()