logo
down
shadow

Smoothening a normal/gaussian plot in matplotlib


Smoothening a normal/gaussian plot in matplotlib

By : Dmitry
Date : November 22 2020, 10:33 AM
I think the issue was by ths following , I tried to reproduce your array with the following code. a is your array.
code :
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.mlab as mlab

a = np.random.randn(500)*5
plt.plot(a, mlab.normpdf(a, np.mean(a), np.std(a)))
plt.show()
n = mlab.normpdf(a, np.mean(a), np.std(a))
ind = np.argsort(a)
a = a[ind]
n = n[ind]
plt.plot(a,n)
plt.show()
plt.plot(a, mlab.normpdf(a, np.mean(a), np.std(a)), 'o')


Share : facebook icon twitter icon
Trying to plot multivariate Gaussian dist. in a 3D plot matplotlib returns an empty figure

Trying to plot multivariate Gaussian dist. in a 3D plot matplotlib returns an empty figure


By : ww.li
Date : March 29 2020, 07:55 AM
I wish this helpful for you I'm no expert with 3D-plots in matplotlib, but I believe your data wrong.
As you can see in the sourcecode in this tutorial, your X,Y and Z data have to be 2-dimensional arrays. Your X and Y are one-dimensional, and your Z is a simple list.
Matplotlib: Plot path integral of curve under bivariate gaussian

Matplotlib: Plot path integral of curve under bivariate gaussian


By : barataatomica
Date : March 29 2020, 07:55 AM
To fix this issue I am trying to plot the path (or line) integral under a (negative log) bivariate gaussian. I am aiming to produce something that looks like the different stages of this neat little gif I found a wikipedia.
code :
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.mlab import bivariate_normal
import scipy.interpolate


def func(X, Y):
    # Bivariate gaussian
    return -np.log(bivariate_normal(X, Y))

sns.set(style="white", palette="muted", color_codes=True)


def create_smoth_path(points):
    data = np.array(points).T

    tck, u = scipy.interpolate.splprep(data, s=0)
    unew = np.arange(0, 1.01, 0.01)
    out = scipy.interpolate.splev(unew, tck)
    return out


def pathIntegral(path, func_):
    x = path[0]
    y = path[1]
    z = func_(x, y)
    z1 = np.zeros((2, x.shape[0]))
    z1[1] = z

    x1 = np.tile(x, (2, 1))
    y1 = np.tile(y, (2, 1))

    start = min(x.min(), y.min())-2
    stop = max(x.max(), y.max())+2
    a = np.arange(start, stop, 0.5)
    b = a
    X, Y = np.meshgrid(a, b)
    Z = func_(X, Y)

    ax = plt.subplot2grid((3,1), (0,0), rowspan=2, projection='3d')
    ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=plt.cm.gist_heat_r, alpha=0.2, linewidth=0.1)

    ax.plot_surface(x1, y1, z1, rstride=1, cstride=1, color='g')
    ax.scatter(x[0], y[0], 0, c='k', marker='o')
    ax.scatter(x[-1], y[-1], 0, c='k', marker='o')
    ax.plot(x1, y1, color='b')
    dx = np.diff(x)
    dy = np.diff(y)
    dr = np.sqrt(dx**2 + dy**2)
    r = np.concatenate((np.zeros(1), np.cumsum(dr)))
    ax = plt.subplot2grid((3,1), (2,0))
    ax.set_xlim([np.min(r), np.max(r)])
    plt.plot(r, z, 'r')
    plt.xlabel('r')
    plt.ylabel('z(x, y)')
    plt.show()

# path
points = [(-5, -6), (-1, -3), (1, -2), (2, 1), (0, 0), (2, 2), (4, 3), (4, 3.5), (5, 5)]

r = create_smoth_path(points)
pathIntegral(r, func)
Plot a bivariate gaussian using Matplotlib

Plot a bivariate gaussian using Matplotlib


By : fang
Date : March 29 2020, 07:55 AM
like below fixes the issue Your problem is not actually with the spatial extent of your probability distribution functions, but rather with the normalisation you use to display your composition functions. In particular, as a value of zero should mean zero probability and it is of course favourable if that value is tied to the same colour in each frame. The normalisation you use in your code, namely
code :
normPDF = PDF - PDF.min()
normPDF = normPDF / normPDF.max()
normPDF = (PDFs[0]-PDFs[1])/max(PDFs[0].max(),PDFs[1].max())
cfs = ax.contourf(X, Y, normPDF, cmap='viridis', alpha = 1, levels=np.linspace(-1,1,10))
how to plot 3d gaussian distribution with matplotlib

how to plot 3d gaussian distribution with matplotlib


By : varun kumar
Date : March 29 2020, 07:55 AM
may help you . this is based on documentation of mpl_toolkits and an answer on SO based on scipy multinormal pdf
How to plot the pdf of a 1D Gaussian Mixture Model with matplotlib

How to plot the pdf of a 1D Gaussian Mixture Model with matplotlib


By : Sumit
Date : March 29 2020, 07:55 AM
I wish this helpful for you You can literally draw samples from a Gaussian mixture model and plot the empirical density / histogram too:
Related Posts Related Posts :
  • Testing logging output with pytest
  • How do I change my default working directory for Python (Anaconda) on VSCode?
  • .lower() for x in list, not working, but works in another scenario
  • Program gives error "List indices must not be string"
  • pyqt: Memory Usage
  • Confused about classes in Learn Python the Hard Way ex43?
  • Extracting unrecognized information from many CSV files
  • How do I connect to Postgresql server from Python?
  • Append rows to a pandas DataFrame without making a new copy
  • Scrapy: Importing a package from the project that's not in the same directory
  • launching Excel application using Python to view the CSV file , but CSV file is opening in read mode and cant view the d
  • Making a list in user-defined functions
  • Pyserial microcontroller to host communication
  • Plotting a line in between subplots
  • function not returning value. Error "NameError: name 'urlss' is not defined"
  • How to perform cartesian product with Tensorflow?
  • Multiple independent random number streams from single seed
  • I Need a simple and short python3 code that count secounds in a background process
  • No module named constants
  • from django 1.4 to django 1.5- argument 'verify_exists' what s replacement?
  • Slash replacement inside a raw string
  • Reordering columns/rows of a pivot_table?
  • MySQLdb.cursors.Cursor.execute does not work
  • Python module being reimported when imported at different places
  • Is the Session object from Python's Requests library thread safe?
  • Python Regex: Finding First and Last Names
  • Order by selection in List view of OpenERP 7.0
  • Reading input values in ipython notebook
  • List of dictionaries - how to read a specific value in a dictionary
  • writing os.system output to file
  • Create dictionary from points list and multiple attribute lists
  • How to write a table line by line with for loop
  • Map projection and forced interpolation
  • Django FBV's "render_to_response" equivalent in Class-Based-View?
  • Paramiko raises "SFTPError: Garbage packet received"
  • python pandas operations on columns
  • python list appending is not working
  • Speeding up matplotlib scatter plots
  • For each element of the list find closest date from a different list
  • How to prepend new rows at the beginning of an existing csv file?
  • how to make database robust to process kills with sqlite postgress and sqlalchemy?
  • finding a set of ranges that a number fall in
  • New line in python print() function
  • How to clear os.environ value for only one Variable in Python
  • Why does python append a modulo(%) operator to the end of a newly opened file?
  • recursive function or non-recursive that doesnt use 2 ** approach
  • Extract floats from a String using regular expression
  • How to solve: ImportError: No module named django.core.wsgi in Apache2 log?
  • What's the most concise way to include multiple statements in a Python switch case?
  • python xml pretty print not working
  • Can we use NumPy in writing a website?
  • Called bashscript doesn't start up GNU screen session
  • Reading fortran direct access data and writing formatted data - faster with python than with fortran?
  • Language supporting nested definition of functions
  • Find elements which exists in the most of the lists
  • Templating library in node.js similar to Jinja2 in Python?
  • Python Syntax Error, 'break' is outside the loop
  • Replacing spaces with hyphens
  • How to open a csv file in Microsoft Excel in Python?
  • ModuleNotFoundError: No module named 'users'
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org