histogram

How to get a three-dimensional histogram from two-dimensional data?

别说谁变了你拦得住时间么 提交于 2019-12-02 10:12:15
I have two data lists: x=[2006, 2007, 2008, 2009, 2010] y=[700, 560, 450, 500, 570] I needed to build a regular histogram (it was not difficult). But I also need a three-dimensional diagram, as in the figure . I tried various options (for example, bar3d), but it turns out not that. Help, please. import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_subplot(111, projection='3d') x= [float(i) for i in input('Input x ').split()] y= [float(i) for i in input('Input y ').split()] hist, xedges, yedges = np.histogram2d(x, y, bins=(4,4)) xpos, ypos = np.meshgrid(xedges[:-1]

R: Density plot with colors by group?

北慕城南 提交于 2019-12-02 08:47:59
问题 I have data from 2 populations. I'd like to get the histogram and density plot of both on the same graphic. With one color for one population and another color for the other one. I've tried this (example): library(ggplot2) AA <- rnorm(100000, 70,20) BB <- rnorm(100000,120,20) valores <- c(AA,BB) grupo <- c(rep("AA", 100000),c(rep("BB", 100000))) todo <- data.frame(valores, grupo) ggplot(todo, aes(x=valores, fill=grupo, color=grupo)) + geom_histogram(aes(y=..density..), binwidth=3)+ geom

R: Control number of histogram bins

旧时模样 提交于 2019-12-02 08:26:24
I am using the hist-function to analyze some data I generated. For an analysis-assay I would like to precisely control the number of histogram bins. I know the "break-argument" and I can see that in many cases the number of bins is in a direct relationship to the number of breaks (i.e. no_bins = no_breaks + 1). Due to R's algorithm this is not always the case. Is there a way to force R to output a specific number of bins? Let me know if I need to specify further details. Best and many thanks! From ?hist , there are several options for controlling the bins through the breaks argument. breaks

Python keeps overwriting hist on previous plot but doesn't save it with the desired plot

强颜欢笑 提交于 2019-12-02 07:58:06
I am saving two separate figures, that each should contain 2 plots together. The problem is that the first figure is ok, but the second one, does not gets overwritten on the new plot but on the previous one, but in the saved figure, I only find one of the plots : This is the first figure , and I get the first figure correctly : import scipy.stats as s import numpy as np import os import pandas as pd import openpyxl as pyx import matplotlib matplotlib.rcParams["backend"] = "TkAgg" #matplotlib.rcParams['backend'] = "Qt4Agg" #matplotlib.rcParams['backend'] = "nbAgg" import matplotlib.pyplot as

matlab plot histogram indicating sum of each character inside a file

╄→尐↘猪︶ㄣ 提交于 2019-12-02 07:51:37
I have 400 files, each one contains about 500000 character, and those 500000 characters consists only from about 20 letters. I want to make a histogram indicating the most 10 letters used (x-axis) and number of times each letter is used (y-axis). how can i make it. beaker Since you have an array of uchar , you know that your elements will always be in the range 0:255 . After seeing Tamás Szabó's answer here I realized that the null character is exceedingly unlikely in a text file, so I will just ignore it and use the range 1:255 . If you expect to have null characters, you'll have to adjust

Combining histograms with a density plot in R

谁都会走 提交于 2019-12-02 07:49:12
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 6 years ago . It seems that I have a problem of scaling between histograms and density lines when I combine both in one plot. There is a clear visual difference between the density curve plotting alone and the combination of the two. What is the solution to have the same shape and scale between the two plots (density alone and density when combining it with histo)? I use this code: hist

Compare multiple histograms in file OpenCV

南笙酒味 提交于 2019-12-02 07:32:40
I have a dataset of images, where I create the histogram of every image and then I want to store (write) them into a file, so that for every new image I use as input, I compare the histogram of this image with the ones I already have in the file and find if they are identical. The code so far is this: import numpy as np import cv2 import os.path import glob import matplotlib.pyplot as plt import pickle index = {} #output dic out = { 1: {}, 2: {}, 3: {}, } for t in [1]: #load_files files = glob.glob(os.path.join("..", "data", "train", "Type_{}".format(t), "*.jpg")) no_files = len(files)

How to Fit to The Outer Shell of a Function

拟墨画扇 提交于 2019-12-02 06:35:35
I am trying to make a gaussian fit on a function that is messy. I want to only fit the exterior outer shell (these are not just the max values at each x, because some of the max values will be too low too, because the sample size is low). from scipy.optimize import curve_fit def Gauss(x, a, x0, sigma, offset): return a * np.exp(-np.power(x - x0,2) / (2 * np.power(sigma,2))) + offset def fitNormal(x, y): popt, pcov = curve_fit(Gauss, x, y, p0=[np.max(y), np.median(x), np.std(x), np.min(y)]) return popt plt.plot(xPlot,yPlot, 'k.') plt.xlabel('x') plt.ylabel('y') plt.title('Y(x)') x,y = xPlot

Define bar chart colors for Pandas/Matplotlib with defined column

与世无争的帅哥 提交于 2019-12-02 06:23:21
I have a dataframe "table" like this: SAMPLE RANK VALUE CAT 3 N DOG 1 N FISH 4 Y ANT 2 N HORSE 5 N How can I JUST COLOR the 3rd histogram column, given that there is a "Y" in the VALUE column? I would like it to look like this: So far I have : table.plot('SAMPLE','RANK', hue="VALUE", palette={"Y": "r", "N": '0.75'}, kind='bar') but this does not work You may achieve the desired effect by mapping VALUE column to desired colors: colors = {'N':'#00BEC5', 'Y':'#F9746A'} df.sort_values('RANK', inplace=True) df.plot.bar(x='SAMPLE', y='RANK',color= df['VALUE'].map(colors)); 来源: https://stackoverflow

GNUplot: how to plot rowstacked bar chart using color codes in data?

萝らか妹 提交于 2019-12-02 05:33:14
问题 I have the following sample data: col1 2 0 1 1 col2 1 1 0 0 col3 1 1 1 0 col4 1 1 2 1 col5 1 1 1 1 col6 2 0 1 1 col7 1 1 2 2 col8 1 1 2 1 columns #4 and #5 are the color codes for columns #2 and #3. For example, I want '1' for green, 2 for white, and 0 for orange. Here is how I tried to plot it: set key off unset border unset xtics unset ytics set style data histograms set style histogram rowstacked set boxwidth 1 relative set style fill solid 1.0 border -1 set yrange [0:2] set lmargin 0 set