Plot a histogram such that bar heights sum to 1 (probability)

I'd like to plot a normalized histogram from a vector using matplotlib. I tried the following: plt.hist(myarray, normed=True) as well as: plt.hist(myarray, normed=1) but neither option...

How to store an image in a variable

I would like to store the image generated by matplotlib in a variable raw_data to use it as inline image. import os import sys os.environ['MPLCONFIGDIR'] = '/tmp/' import...

How do you create a legend for a contour plot in matplotlib?

I can't seem to find the answer anywhere! I found a discussion here, but trying this I get a TypeError: 'NoneType' object is not iterable: >>> import numpy as np >>> import matplotlib.pyplot as...

How to normalize a histogram in python?

I'm trying to plot normed histogram, but instead of getting 1 as maximum value on y axis, I'm getting different numbers. For array k=(1,4,3,1) import numpy as np def plotGraph(): import...

How to center labels in histogram plot

I have a numpy array results that looks like [ 0. 2. 0. 0. 0. 0. 3. 0. 0. 0. 0. 0. 0. 0. 0. 2. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. ...

Multiple histograms in Pandas

I would like to create the following histogram (see image below) taken from the book "Think Stats". However, I cannot get them on the same plot. Each DataFrame takes its own subplot. I have the...

How to clear memory completely of all matplotlib plots

I have a data analysis module that contains functions which call on the matplotlib.pyplot API multiple times to generate up to 30 figures in each run. These figures get immediately written to disk...

Seaborn factor plot custom error bars

I'd like to plot a factorplot in seaborn but manually provide the error bars instead of having seaborn calculate them. I have a pandas dataframe that looks roughly like this: model output...

How do I change the figure size for a seaborn plot?

How do I change the size of my image so it's suitable for printing? For example, I'd like to use to A4 paper, whose dimensions are 11.7 inches by 8.27 inches in landscape orientation.

Fullbody Detection Using OpenCV Haar Cascades

I want to detect the full body of human within image using OpenCV fullbody Haar Cascades. Here's my code: import numpy as np import cv2 from matplotlib import pyplot as plt bodydetection =...

How to draw a line with matplotlib?

I cannot find a way to draw an arbitrary line with matplotlib Python library. It allows to draw horizontal and vertical lines (with matplotlib.pyplot.axhline and matplotlib.pyplot.axvline, for...

How to make a .py file to .exe from Ubuntu to run it on Windows?

I have made a python script using python3.5, it uses many packages like tkinter, matplotlib, pylab etc. I want to convert .py file to .exe so that I can give it to people to run on windows....

How to add x-axis labels to every plot in a seaborn figure-level plot

I'm using Seaborn to make a Factor Plot. In total, I have 4 'sub plots' (and use col_wrap =2, so I have 2 rows, each containing 2 sub plots). Only the 2 sub plots at the very bottom of the grid...

How do I incrementally add rows in Pandas Dataframe?

I am calculating the open-high-low-close (OHLC) of data for a duration of each 15 mins from 9:15 to 15:30 and want to store the OHLC values in a dataframe in each new row. ohlc =...

Pandas Dataframe line plot display date on xaxis

Compare the following code: test = pd.DataFrame({'date':['20170527','20170526','20170525'],'ratio1':[1,0.98,0.97]}) test['date'] = pd.to_datetime(test['date']) test = test.set_index('date') ax =...

How to sort bars in a bar plot in ascending order

I created a bar plot using matplotlib.pyplot and seaborn libraries. How can I sort bars in increasing order according to Speed? I want to see the bars with the lowest speed on the left and the...

Jupyter Notebook - Cannot Connect to Kernel

I've tried installing jupyter notebook using pip3 install jupyter. Every time i launch a new jupyter notebook, the notebook is unable to connect to the kernel. See screenshot below Attaching my...

How to use figures stored in variables as subplots

Assume a set of 4 matplotlib figures stored in variables fig1 to fig4. import matplotlib.pyplot as plt fig1 = plt.figure() plt.plot([1, 2, 3, 4]) fig2 = plt.figure() plt.plot([2, 2, 2, 2]) fig3...

How can I plot the standard error on the error bars in seaborn's barplot?

I have a nice figure that is plotted with generic code as follows: import seaborn as sns sns.barplot(data=df, x='X', y='y', hue='HUE', capsize=.1) The errorbars by default display the 95%...

Seaborn: Is there a better way to wrap the text in my bar plot?

I am writing a function for bar plots and have encountered another small problem. I have some ytick labels that are too long, causing my y axis label not able to be seen. I'm only able to see the...

Changed frequency of ticks in Pandas '.bar' plot, but messed up the actual bars

how's your self-isolation going on? Mine rocks, as I'm drilling through visualization in Python. Recently, however, I've ran into an issue. I figured that .plot.bar() in Pandas has an uncommon...

Is it possible to suppress Matplotlib/Seaborn output in Jupyter notebook?

All - reaching out for some guidance, if any available, to help solve this somewhat frustrating issue. I am defining a function that creates a correlation matrix using Seaborn's annotated heatmap....

Random number generation following a Poisson distribution

I have prepared a code in Python to do random sampling of beam structure and looking for photons. The evolution of photons with time follows a Poisson distribution. The beam structure I am...

How to plot distributions for multiple columns on one graph

I want to create a visualization of the distribution of the attributes across gender in one graph. Is there a way to do that in Python? I used px.boxplot, but I can only do one column at a...

How to add Error Bar to Matplotlib line plot

I have the following dataset which I use to plot a line plot. The plot is obtained as the mean of values obtained from the data. I want to add error bars to this plot which shall show the standard...

How to change the figure size of a displot

I am new to Seaborn, and I am having some trouble changing my figure size. I have looked at examples and adapted it to my code, but nothing seems to be happening. When executing the code, my...

How to plot a stacked seaborn histogram colored from a different column

My dataset is like this Days Visitors Tuesday 23 Monday 30 Sunday 120 Friday 2 Friday 30 Tuesday 13 Monday 20 Saturday 100 How can I plot a histogram for this...

Matplotlib kills kernel on Jupyter

Hi, I'm taking a machine learning course on udemy and im trying to run the following: %matplotlib inline import matplotlib.pyplot as plt The issue is that once I run this, it kills the kernel...

Tensorflow Keras URL fetch failure for Training Dataset

I'm trying to import my training dataset for my CNN (30,000 images), but there's something about this line that breaks the program. data_dir = tf.keras.utils.get_file(origin=dataset_url, ...

How to plot a regression line on a timeseries line plot

I have a question about the value of the slope in degrees which I have calculated below: import pandas as pd import yfinance as yf import matplotlib.pyplot as plt import datetime as dt import...