histogram

Histogram conditional fill color

你离开我真会死。 提交于 2019-11-28 11:11:10
I would like to make a histogram where the fill color changes depending on the low end of the bin. I do not want a manual fill. This answer seems promising, but I could not transition it successfully to a histogram and two-value (not gradient) color scheme. I believe the solution may be some ifelse logic within geom_histogram(fill= ) but I don't know how to access the bin starting value. For example, in the below histogram, I would like to color revenue bins over $100,000 red to show the high-revenue customers. library(ggplot2) library(scales) n <- 10000 cust <- data.frame(cust_id=1:n,cust_rev

Matplotlib 2D histogram seems transposed

我是研究僧i 提交于 2019-11-28 11:02:12
问题 I have the following code to plot a 2d histogram in pyplot: #!/usr/bin/env python import numpy as np import matplotlib.pyplot as plt MIN, MAX, num = .001, 5000, 500 minn=1 maxx=1000 zbins = 10 ** np.linspace(np.log10(MIN), np.log10(MAX), num) x=np.linspace(100,600,50000) y=np.linspace(0,500,50000) fig1 = plt.figure(1) counts1,xedges1,edges1,d=plt.hist2d(x,y,bins=zbins) mesh1 = plt.pcolormesh(zbins, zbins, counts1) plt.xlim([minn, maxx]) plt.ylim([minn, maxx]) plt.gca().set_xscale("log") plt

R - Customizing X Axis Values in Histogram

喜夏-厌秋 提交于 2019-11-28 10:58:29
I want to change the values on the x axis in my histogram in R. The computer currently has it set as 0, 20, 40, 60, 80, 100. I want the x axis to go by 10 as in: 0,10,20,30,40,50,60,70,80,90,100. I know to get rid of the current axis I have to do this (hist(x), .... xaxt = 'n') and then axis(side = 1) ..... But how do I get it to show the numbers that I need it to show? Thanks. The answer is right there in ?axis ... dat <- sample(100, 1000, replace=TRUE) hist(dat, xaxt='n') axis(side=1, at=seq(0,100, 10), labels=seq(0,1000,100)) 来源: https://stackoverflow.com/questions/8481610/r-customizing-x

Animation of histograms in subplot

落爺英雄遲暮 提交于 2019-11-28 10:37:34
I have the following animated subplots that simulate histograms of four different distributions: import numpy from matplotlib.pylab import * import matplotlib.animation as animation n = 100 # generate 4 random variables from the random, gamma, exponential, and uniform distributions x1 = np.random.normal(-2.5, 1, 10000) x2 = np.random.gamma(2, 1.5, 10000) x3 = np.random.exponential(2, 10000)+7 x4 = np.random.uniform(14,20, 10000) fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2) def updateData(curr): if curr == n: a.event_source.stop() ax1.hist(x1[:curr], normed=True, bins=20, alpha=0.5) ax2

openCV Gaussian blur/smoothing of 3D Matrix/Histogram

我的未来我决定 提交于 2019-11-28 10:18:19
问题 I have a (3D) Histogram which I like to apply Gaussian smoothing on: cv::MatND Hist; In the 1D and 2D cases I blur it via: cv::GaussianBlur(Hist, Hist, cv::Size(1,3), 1.0);// 1D case cv::GaussianBlur(Hist, Hist, cv::Size(3,3), 1.0);// 2D case But I struggle to apply Gaussian blurring in the 3D case. Has anyone got an idea how to attempt this? 回答1: Try use separable kernels like shown here: http://www.programming-techniques.com/2013/03/gaussian-blurring-using-separable.html 来源: https:/

How can I create a histogram from aggregated data in R?

做~自己de王妃 提交于 2019-11-28 10:06:15
I have a data frame that has a format like the following: Month Frequency 2007-08 2 2010-11 5 2011-01 43 2011-02 52 2011-03 31 2011-04 64 2011-05 73 I would like to create a histogram from this data, using X bins (X will probably be around 15, but the actual data has over 200 months), and using the data from the frequency column as the frequency for each bin of the histogram. How can I accomplish this? I've tried two approaches so far, with the hist() and barplot() commands. The problem with hist() is that it does not seem to give me any way to specify that I want to use the frequency column

Change matplotlib.bar Order in python 2.7 [duplicate]

喜你入骨 提交于 2019-11-28 09:49:46
问题 This question already has answers here : Pyplot sorting y-values automatically (2 answers) Closed last year . In this example: import matplotlib.pyplot as plt colors = ['white', 'orange', 'green', 'purple'] rates = ['5','5','4','3'] plt.bar(colors, rates) the bars in the plot are ordered by the alphabetic order. How do I make them to show in the same order as they are in the code (from highest to lowest rate)? 回答1: Matplotlib 2.1 provides the new option to use strings as input to its plotting

Normalizing a histogram and having the y-axis in percentages in matlab

允我心安 提交于 2019-11-28 09:28:13
Edit: Alright, so I answered my own question, by reading older questions a bit more. I apologize for asking the question! Using the code Y = rand(10,1); C = hist(Y); C = C ./ sum(C); bar(C) with the corresponding data instead of the random data worked fine. Just need to optimize the bin size now. Good day, Now I know that you must be thinking that this has been asked a thousand times. In a way, you are probably right, but I could not find the answer to my specific question from the posts that I found on here, so I figured I might as well just ask. I'll try to be as clear as possible, but

How to add gaussian curve to histogram created with qplot?

对着背影说爱祢 提交于 2019-11-28 09:20:49
I have question probably similar to Fitting a density curve to a histogram in R . Using qplot I have created 7 histograms with this command: (qplot(V1, data=data, binwidth=10, facets=V2~.) For each slice, I would like to add a fitting gaussian curve. When I try to use lines() method, I get error: Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet What is the command to do it correctly? joran Have you tried stat_function ? + stat_function(fun = dnorm) You'll probably want to plot the histograms using aes(y = ..density..) in order to plot the density values

ggplot histogram with % and percentage *labels*

微笑、不失礼 提交于 2019-11-28 08:56:30
问题 I want to use ggplot to make a histogram using percentages. I found this answer that gets me part of the way there. However, I also want to place a label at the top of each histogram bar showing the actual percentage. Here is my code and a link to the output: p <- ggplot(mtcars, aes(x = hp)) + geom_bar(aes(y = (..count..)/sum(..count..)), binwidth = 25) + ## scale_y_continuous(labels = percent_format()) #version 3.0.9 scale_y_continuous(labels = percent) #version 3.1.0 p <- p + stat_bin(aes