How add a plot to histogram in seaborn.jointplot? [duplicate] - python

This question already has answers here:
How to overlay a Seaborn jointplot with a "marginal" (distribution histogram) from a different dataset
(4 answers)
How to add manually customised seaborn plots to JointGrid/jointplot
(1 answer)
Closed 3 days ago.
I have a seaborn jointplot:
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
def plot():
random_matrix=np.random.standard_normal((1000,2))
df=pd.DataFrame(random_matrix,columns=["x","y"])
print(df)
b=10
plot=sns.jointplot(data=df,x="x", y="y",ratio=1,s=1,marginal_ticks=True,marginal_kws=dict(bins=b))
plot.fig.suptitle("title")
plot.figure.savefig("./plot.png")
That produces the following plot: plot
Now let's say that I have already fit a function to one of these histograms (let's say to the upper one). How could I plot this function on that histogram?
I just started to use the seaborn package so I have no intuition how one can do that. Before I plotted histograms and a scatter plot separately in matplotlib and put them together in such a composition but I want to use a more automatic tool and seaborn seems to be the one.

Related

Draw a Bell Curve on my Distribution Sample [duplicate]

This question already has answers here:
Fitting a Normal distribution to 1D data
(4 answers)
Python: Visualize a normal curve on data's histogram
(1 answer)
How do I draw a histogram for a normal distribution using python matplotlib?
(3 answers)
Fit a curve to a histogram in Python
(2 answers)
How to draw a matching Bell curve over a histogram?
(1 answer)
Closed 1 year ago.
I have the following piece of code:
from pyspark.sql import DataFrame
import plotly.express as px
import matplotlib.pyplot as plt
dfPy = sqlContext.table("df")
pd = dfPy.toPandas()
pd[['col4']].plot(kind='hist', bins=[0,10,20,30,40,50,60,70,80,90,100], rwidth=0.8)
plt.show()
And I get to see the following result of running it in the Apache Zeppelin notebook:
As it can be seen that I have two issues:
How can I draw a bell curve? Seems the distribution is not normal or gaussian like. So I suppose that I should do some data transformation. Correct?
How can I now draw a bell curve on the resulting histogram?

Problem with import matplotlib.pyplot as plt in python (Anaconda - Spyder) [duplicate]

This question already has answers here:
How to display a graph in ipython notebook
(2 answers)
Closed 2 years ago.
i'm newbie in python but i don't know how to solve this problem
I need an histogram in my code. I use this:
import matplotlib.pyplot as plt
plt.hist(datos["Ozone"], bins=10)
Note: datos is a dataframe.
I tested with other more basic examples, but never show the graph of the histogram.
I think is a problem with the Console, but i don't know how solve the problem.
You have to write:
plt.show()
at the end to see your plot.
EDIT:
In case you are using jupyter notebooks, there is no need for plt.show(). You can just add two lines of code as follows:
import matplotlib.pyplot as plt
%matplotlib qt
%matplotlib inline
plt.hist(datos["Ozone"], bins=10)

How to create stacked histogram using matplotlib

I am very new to Python and start to learn matplotlib recently. I have a dataset which have one 5 independent variables and 1 dependent variable. I want to create a stacked histogram which can show the variable distribution within independent variable.
Here is my raw data-
Country, age, new_use, source and total_pages_visited are independent variables. Converted is dependent variable. I want to create separate stacked histogram for each independent variables. And in each histogram, it shows the distribution of variable and mark the different category of 'converted' in different color.
I think what you want is stacked bar plot and you can use pandas to achieve it.
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
df = pd.DataFrame(np.asarray([[1,2],[3,4],[5,6]]),index=['A','B','C'], columns=['Converted-Yes', 'Converted-No'])
df.plot.bar(stacked=True)
plt.show()
The above code generates the plot:

Is it possible to plot multiple histogram the same way like tensorboard does in a notebook [duplicate]

This question already has answers here:
frequency trail in matplotlib
(2 answers)
Demo of Joypy (joyplots in python) not working?
(1 answer)
How do I visually stack multiple line graphs above each other in python?
(1 answer)
Closed 4 years ago.
Given some data frame we can easily plot the histogram for each column in a notebook like so:
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
df.hist()
But instead of having one plot per column is it possible to plot it in one plot the same way tensorboard does it?
Is a 3D histogram the best we can do? Maybe using something different then matplotlib?

Importing seaborn in python script messing up plot style

Attached below are two plots. The only difference in the script that produced them is that the second one had an additional line:
import seaborn as sns
I am not setting any seaborn style yet. Just importing seaborn is changing plot style though, even in plots not using seaborn. Is there any way I can import seaborn (to be used in other plots), and not have the style changed for plots that do not use it?
Check this
import seaborn.apionly as sns or from seaborn.apionly import lmplot
http://stanford.edu/~mwaskom/software/seaborn/whatsnew.html

Categories

Resources