How can I fix the histogram


aa

I am trying to draw a very simple histogram using python. Here is my code:

from numpy import *
from matplotlib.pyplot import*
from random import*
nums = []
N = 10
for i in range(N):
    a = randint(0,10)
    nums.append(a)

bars= [0,1,2,3,4,5,6,7,8,9]
hist(nums)

show()

this is the result

How to place bar chart at integer positions? Why is my chart showing floating point numbers too?

Tmdavison

You make barsit but don't use it. Everything works fine if the binsoption is set histtobars

bars= [0,1,2,3,4,5,6,7,8,9]
hist(nums,bins=bars)

enter image description here

To set yticksto only integer values, you can use the slave module:MultipleLocatormatplotlib.ticker

from numpy import *
from matplotlib.pyplot import*
import matplotlib.ticker as ticker
from random import*

nums = []
N = 10
for i in range(N):
    a = randint(0,10)
    nums.append(a)

bars= [0,1,2,3,4,5,6,7,8,9]
hist(nums,bins=bars)

gca().yaxis.set_major_locator(ticker.MultipleLocator(1))

show()

enter image description here

Related


How can I fix the histogram

aa I am trying to draw a very simple histogram using python. Here is my code: from numpy import * from matplotlib.pyplot import* from random import* nums = [] N = 10 for i in range(N): a = randint(0,10) nums.append(a) bars= [0,1,2,3,4,5,6,7,8,9] hist(

How can I fix the code used to draw the histogram?

request20 Sorry if this is the basics, I'm new to R and starting here. I would like to plot a histogram of the following data (each sample has a Shannon diversity metric representing the abundance and abundance of species in each sample). Here is my data, curr

How can I fix the code used to draw the histogram?

request20 Sorry if this is the basics, I'm new to R and starting here. I would like to plot a histogram of the following data (each sample has a Shannon diversity metric representing the abundance and abundance of species in each sample). Here is my data, curr

How can I fix the code used to draw the histogram?

request20 Sorry if this is the basics, I'm new to R and starting here. I would like to plot a histogram of the following data (each sample has a Shannon diversity metric representing the abundance and abundance of species in each sample). Here is my data, curr

How can I fix the code used to draw the histogram?

request20 Sorry if this is the basics, I'm new to R and starting here. I would like to plot a histogram of the following data (each sample has a Shannon diversity metric representing the abundance and abundance of species in each sample). Here is my data, curr

How can I fix the code used to draw the histogram?

request20 Sorry if this is the basics, I'm new to R and starting here. I would like to plot a histogram of the following data (each sample has a Shannon diversity metric representing the abundance and abundance of species in each sample). Here is my data, curr

How can I fix it?

Hakunex I want to change: <b class="added-points">0</b> Using javascript on my website. I searched and found document.getElementById("added-points").innerHTML = "9999999999999"; But it is for the id and I search for the class. How to do it? Joe Wilson if you

How can I fix this?

Sagas I have two radio buttons: yes and no When I select "Yes" it should ask "Enter your requirements" and when I select "No" nothing happens. I have tried: <form> <input type="radio" name="question" value="yes">YES <input type="radio" name="question" value="n

How can I fix this?

Sagas I have two radio buttons: yes and no When I select "Yes" it should ask "Enter your requirements" and when I select "No" nothing happens. I have tried: <form> <input type="radio" name="question" value="yes">YES <input type="radio" name="question" value="n

How can I reduce the width of the histogram?

Itsuyama I have plotted a histogram of diagnostics, which I modeled as a Poisson distribution in python. I need to reduce the width of the rectangles in the output graph. I wrote the following line in python. I need the width reduction parameter for this line

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I reduce the width of the histogram?

Itsuyama I have plotted a histogram of diagnostics, which I modeled as a Poisson distribution in python. I need to reduce the width of the rectangles in the output graph. I wrote the following line in python. I need the width reduction parameter for this line

How can I make this histogram in ggplot/R?

Crimea Please find My data qbelow . I have two covariates: q$Studieand q$best.respcorresponding to each of the five different studies reporting the best response after a certain treatment. q$best.respThere are three levels table(q$best.resp) 0 1 2 62 42

How can I represent the classes on the histogram with colors?

Subhankar Nayak I have a column in a dataset which I represent with a pyplot.hist graph. Use grey as a trash can. Another column by which I want to divide the graph is called "Class". There are two categories (0 and 1) in the Category column. I would like to r

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I create a histogram in R?

sara I'm new to working in Unix, so I need help on how to put a histogram together using R in Linux environment? File: 48302 50 0 48303 46 0 48304 45 0 48305 41 15 48306 44 21 48307 74 0 48308 71 0 48309 35 19 48310 66 0 48311 26

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I represent the classes on the histogram with colors?

Subhankar Nayak I have a column in a dataset which I represent with a pyplot.hist graph. Use grey as a trash can. Another column by which I want to divide the graph is called "Class". There are two categories (0 and 1) in the Category column. I would like to r

How can I make this histogram in ggplot/R?

Crimea Please find My data qbelow . I have two covariates: q$Studieand q$best.respcorresponding to each of the five different studies reporting the best response after a certain treatment. q$best.respThere are three levels table(q$best.resp) 0 1 2 62 42

How can I represent the classes on the histogram with colors?

Subhankar Nayak I have a column in a dataset which I represent with a pyplot.hist graph. Use grey as a trash can. Another column by which I want to divide the graph is called "Class". There are two categories (0 and 1) in the Category column. I would like to r

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10