我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用plotly.graph_objs.Histogram()。
def create_data(self): bin_values, bin_edges = bin_datetimes(self.kamervraag_dates, range_years=7, bin_size_days=7) x, y_moving_avg = movingaverage_from_histogram(bin_values, bin_edges, window=8) moving_average_scatter = Scatter( x=x, y=y_moving_avg, mode='lines', name='lopende trend', line=dict( color=COLOR_WARNING, width=3, ), ) hist_data = Histogram( x=self.kamervraag_dates, autobinx=False, xbins=dict( start=(timezone.now() - datetime.timedelta(days=7 * 365)).timestamp() * 1000, end=timezone.now().timestamp() * 1000, size=60 * 60 * 24 * 7 * 1000 ), marker=dict( color=COLOR_INFO, line=dict( color=COLOR_PRIMARY, width=1, ) ), name='vragen per week', ) return [hist_data, moving_average_scatter]
def create_data(self): return [Histogram( x=self.kamervraag_durations, autobinx=False, xbins=dict(start=0, end=100, size=1), marker=dict( color=COLOR_INFO, line=dict( color=COLOR_PRIMARY, width=2, ) ), )]
def replot(self, app_state): self.bins = int(app_state['bins']) hist_data = np.histogram(self.likes, bins = self.bins) binsize = hist_data[1][1] - hist_data[1][0] trace = go.Histogram( x=self.likes, autobinx=False, xbins=dict( start=hist_data[1][0], end=hist_data[1][-1]+1, size=binsize ) ) data = [trace] fig = { 'data': data, 'layout': { 'xaxis': { 'title': 'Number of likes', }, 'yaxis': { 'title': 'Count', }, 'bargroupgap' :0.05, } } messages = [ { 'id': 'hist', 'task': 'newPlot', 'data': fig['data'], 'layout': fig['layout'] } ] return messages
def summarize_plots(data, prediction_variable, legend=True): # !------- Check the parameters -------! typeErrors = [] # ----- Check "data" parameter ----- if not isinstance(data, pd.DataFrame): typeErrors.append("data parameter must be a Pandas Data Frame.") # ----- Check "prediction_variable" parameter ----- if not isinstance(prediction_variable, str): typeErrors.append("prediction_variable must be a string.") if isinstance(prediction_variable, np.ndarray) and column.ndim >= 2: typeErrors.append("column parameter must not be a " + \ "multil-dimensional numpy array.") # ----- Check "legend" parameter ----- if not isinstance(legend, bool): typeErrors.append("legend parameter must be a boolean") if typeErrors: raise TypeError(typeErrors) plots = [] box_plots = [] histograms = [] map_plots = [] # We will look at the data and see if there's some kind of # pattern for the bar_plots = [] data_types = ('float64', 'int64', 'int32', int, float) plot_titles_numerical = [] plot_titles_string = [] for column in data: column_type = str(data[column].dtype) if column_type in data_types: # If there's a number in the column # Check if it's a binary variable if (len(data[column].unique()) == 2) and \ ((1 in data[column].unique()) and (0 in data[column].unique())): # Make a bar plot pass else: # It must be numerical fig_box_w = tbs_plot.box_whisker_plot(data[column], column, plot=False) fig_histo = go.Histogram(x=data[column]) plots.append(fig_box_w) plots.append(fig_histo) #box_plots.append(fig_box_w) #histograms.append(fig_histo) plot_titles_numerical.append(column) plot_titles_numerical.append(column) row = (len(plots)/2) tbs_plot.ml_plot_subplots(figs = plots, rows=int(row), cols=2, title="Eezzy Summary", subplot_titles=plot_titles_numerical, legend=False)