From gautham949 at gmail.com Mon Dec 5 01:25:46 2022 From: gautham949 at gmail.com (Gautham) Date: Mon, 5 Dec 2022 11:55:46 +0530 Subject: [Matplotlib-users] How to match color bar in scatter plot with the value of scatter point size? Message-ID: Hello all, I am trying to generate a scatter plot using dataframe series *x *&* y* and the size of the scatter data point using dataframe series *z*. All is good until I add the color bar, which maps the data in *z*. The resulting plot doesn't make sense to me as the color of the scatter points is all over the plot regardless of the size of scatter data points. Example script: fig, ax = plt.subplots() splot = ax.scatter(x.to_numpy(), y.to_numpy(), marker= 'o', \ s = scat.to_numpy(), cmap ='viridis_r', c = scat.to_numpy()) fig.tight_layout() plt.colorbar(splot) plt.show() Thanks Gautham -------------- next part -------------- An HTML attachment was scrubbed... URL: From gautham949 at gmail.com Mon Dec 5 03:07:41 2022 From: gautham949 at gmail.com (Gautham) Date: Mon, 5 Dec 2022 13:37:41 +0530 Subject: [Matplotlib-users] How to match color bar in scatter plot with the value of scatter point size? In-Reply-To: References: Message-ID: I should mention that I iterate through a set of x,y, and z arrays and add the color plot outside the loop. fig, ax = plt.subplots() for x, y, z in arrays: splot = ax.scatter(x.to_numpy(), y.to_numpy(), marker= 'o', s = z.to_numpy(), cmap ='viridis_r', c = z.to_numpy()) fig.tight_layout() plt.colorbar(splot) plt.show() Gautham On Mon, Dec 5, 2022 at 11:55 AM Gautham wrote: > Hello all, > > I am trying to generate a scatter plot using dataframe series *x *&* y* > and the size of the scatter data point using dataframe series *z*. > > All is good until I add the color bar, which maps the data in *z*. The > resulting plot doesn't make sense to me as the color of the scatter points > is all over the plot regardless of the size of scatter data points. > > Example script: > > fig, ax = plt.subplots() > splot = ax.scatter(x.to_numpy(), y.to_numpy(), marker= 'o', \ > s = scat.to_numpy(), cmap ='viridis_r', c = > scat.to_numpy()) > fig.tight_layout() > plt.colorbar(splot) > plt.show() > > Thanks > Gautham > > -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From swfiua at gmail.com Mon Dec 5 19:39:01 2022 From: swfiua at gmail.com (swfiua at gmail.com) Date: Mon, 5 Dec 2022 19:39:01 -0500 Subject: [Matplotlib-users] Fwd: How to match color bar in scatter plot with the value of scatter point size? In-Reply-To: References: Message-ID: This code produces plots that look ok to me: from matplotlib import pyplot as plt import numpy as np x = np.random.randint(1,100, 100) y = np.random.randint(1,100, 100) z = np.random.randint(1,100, 100) fig, ax = plt.subplots() splot = ax.scatter(x, y, marker= 'o', s = z, cmap ='viridis_r', c = z) fig.tight_layout() plt.colorbar(splot) plt.show() On Mon, 5 Dec 2022 at 03:08, Gautham wrote: > I should mention that I iterate through a set of x,y, and z arrays and add > the color plot outside the loop. > > fig, ax = plt.subplots() > for x, y, z in arrays: > splot = ax.scatter(x.to_numpy(), y.to_numpy(), marker= 'o', s = > z.to_numpy(), cmap ='viridis_r', c = z.to_numpy()) > > fig.tight_layout() > plt.colorbar(splot) > plt.show() > > Gautham > > On Mon, Dec 5, 2022 at 11:55 AM Gautham wrote: > >> Hello all, >> >> I am trying to generate a scatter plot using dataframe series *x *&* y* >> and the size of the scatter data point using dataframe series *z*. >> >> All is good until I add the color bar, which maps the data in *z*. The >> resulting plot doesn't make sense to me as the color of the scatter points >> is all over the plot regardless of the size of scatter data points. >> >> Example script: >> >> fig, ax = plt.subplots() >> splot = ax.scatter(x.to_numpy(), y.to_numpy(), marker= 'o', \ >> s = scat.to_numpy(), cmap ='viridis_r', c = >> scat.to_numpy()) >> fig.tight_layout() >> plt.colorbar(splot) >> plt.show() >> >> Thanks >> Gautham >> >> > > -- > > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From roberto.zamora1 at unmsm.edu.pe Tue Dec 20 14:14:26 2022 From: roberto.zamora1 at unmsm.edu.pe (Roberto Martin ZAMORA NEVADO) Date: Tue, 20 Dec 2022 14:14:26 -0500 Subject: [Matplotlib-users] Query about Programming Error Message-ID: I am developing a program for research purposes to enter from Tkinter values of mean, standard deviation and ranges, to graph a normal distribution, but it throws me an error of Traceback (most recent call last): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1921, in __call__ return self.func(*args) File "g:\Cursos\Curso B?sico de Python\Prueba 102", line 45, in Graph_Generator x=np.linspace[normal(a.get()), normal(b.get()),(c.get())] TypeError: 'rv_continuous_frozen' object is not callable El c?digo que he desarrollado en visual studio es: from tkinter import* import matplotlib.pyplot as plt import numpy as np from scipy import stats root=Tk() mu=DoubleVar() sigma=DoubleVar() a=DoubleVar() b=DoubleVar() c=DoubleVar() label10=Label(root,text="Media",font=("Times_New_Roman",20)) label10.place(x=180,y=100) entry6=Entry(root,textvariable=mu,font=("Times_New_Roman",20)) entry6.place(x=600, y=100) label11=Label(root,text="Desviaci?n est?ndar",font=("Times_New_Roman",20)) label11.place(x=180,y=200) entry7=Entry(root,textvariable=sigma,font=("Times_New_Roman",20)) entry7.place(x=600, y=200) label12=Label(root,text="Linspace1",font=("Times_New_Roman",20)) label12.place(x=180,y=300) entry8=Entry(root,textvariable=a,font=("Times_New_Roman",20)) entry8.place(x=600, y=300) label13=Label(root,text="Linspace2",font=("Times_New_Roman",20)) label13.place(x=180,y=400) entry9=Entry(root,textvariable=b,font=("Times_New_Roman",20)) entry9.place(x=600, y=400) label14=Label(root,text="Linspace3",font=("Times_New_Roman",20)) label14.place(x=180,y=500) entry10=Entry(root,textvariable=c,font=("Times_New_Roman",20)) entry10.place(x=600, y=500) def Graph_Generator (): normal= stats.norm(mu,sigma) x=np.linspace[normal(a.get()), normal(b.get()),(c.get())] fp= normal.pdf(x) #funci?n de probabilidad plt.plot(x,fp) plt.show() graph_button=Button(root, text="Generate graph", command=Graph_Generator) graph_button.pack(pady=30) root.mainloop() How can I find a solution to this problem? *Ing. Roberto Mart?n Zamora Nevado* *CIP 74861* *Cel. 945990731* -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at cskk.id.au Wed Dec 21 17:50:21 2022 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 22 Dec 2022 09:50:21 +1100 Subject: [Matplotlib-users] Query about Programming Error In-Reply-To: References: Message-ID: On 20Dec2022 14:14, Roberto Martin ZAMORA NEVADO wrote: >I am developing a program for research purposes to enter from Tkinter >values of mean, standard deviation and ranges, to graph a normal >distribution, but it throws me an error of > >Traceback (most recent call last): > File "C:\Program >Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", >line 1921, in __call__ > return self.func(*args) > File "g:\Cursos\Curso B?sico de Python\Prueba 102", line 45, in >Graph_Generator > x=np.linspace[normal(a.get()), normal(b.get()),(c.get())] >TypeError: 'rv_continuous_frozen' object is not callable That suggests that `normal` is a `rv_continuous_frozen` instance. That has a bunch of methods to obtain various things. Looking at the docs for `scipy.stats.norm`: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.norm.html#scipy.stats.norm It looks like your line: normal= stats.norm(mu,sigma) obtains one of these objects. Based on the examples there, maybe you need the distribution's `.pdf` method (probablity distribution function)? Eg in the erroring line: x=np.linspace[normal(a.get()), normal(b.get()),(c.get())] you want to say `normal.pdf(a.get())` and so forth instead of just `normal`? The docs for `rv_continuous_frozen` are here: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_continuous.html#scipy.stats.rv_continuous and it has a list of the methods about a screen or so down the page. I do not know if you want the `.pdf()` method or one of the others. Cheers, Cameron Simpson From vincent.adrien at gmail.com Thu Dec 22 05:11:25 2022 From: vincent.adrien at gmail.com (vincent.adrien at gmail.com) Date: Thu, 22 Dec 2022 11:11:25 +0100 Subject: [Matplotlib-users] Query about Programming Error In-Reply-To: References: Message-ID: <1c4a470c-eecf-372b-d70d-8032c1e47a92@gmail.com> Hi Roberto, Besides the problem of trying to modify the parameters of a frozen distribution instance as pointed out by Cameron, it looks like your example code is missing the display of the graphical elements to define the parameters of the Gaussian distribution that you want to plot. There is also a small typo in your call to `np.linspace` (`np.linspace(...)` and not `np.linspace[...]`). The modified program below seems to work, at least on my computer. Please note that I am no user of tkinter so those parts of the code might not really follow to usual best practices regardind the GUI elements. ```python from tkinter import* import matplotlib.pyplot as plt import numpy as np from scipy import stats root = Tk() # Set up Gaussian parameters with default dummy values mu = DoubleVar(master=root, value=0.0) sigma = DoubleVar(master=root, value=1.0) a = DoubleVar(master=root, value=-5.0) b = DoubleVar(master=root, value=5.0) c = DoubleVar(master=root, value=1000) label10 = Label(root,text="Media", font=("Times_New_Roman", 20)) label10.place(x=180, y=100) entry6 = Entry(root, textvariable=mu, font=("Times_New_Roman", 20)) entry6.place(x=600, y=100) label11 = Label(root, text="Desviaci?n est?ndar", font=("Times_New_Roman", 20)) label11.place(x=180, y=200) entry7 = Entry(root, textvariable=sigma, font=("Times_New_Roman", 20)) entry7.place(x=600, y=200) label12 = Label(root, text="Linspace1", font=("Times_New_Roman", 20)) label12.place(x=180, y=300) entry8 = Entry(root, textvariable=a, font=("Times_New_Roman", 20)) entry8.place(x=600, y=300) label13 = Label(root, text="Linspace2", font=("Times_New_Roman", 20)) label13.place(x=180, y=400) entry9 = Entry(root, textvariable=b, font=("Times_New_Roman", 20)) entry9.place(x=600, y=400) label14 = Label(root, text="Linspace3", font=("Times_New_Roman", 20)) label14.place(x=180, y=500) entry10 = Entry(root, textvariable=c, font=("Times_New_Roman", 20)) entry10.place(x=600, y=500) def Graph_Generator (): # Set up the Gaussian distribution normal = stats.norm(loc=mu.get(), scale=sigma.get()) # Parameters for the display x_min = a.get() x_max = b.get() nb_samples = int(c.get()) # beware that linspace expects an integer # Compute what to plot x = np.linspace(x_min, x_max, nb_samples) fp = normal.pdf(x) #funci?n de probabilidad # Display the results fig, ax = plt.subplots() ax.plot(x, fp) ax.set_xlim(x_min, x_max) plt.show() graph_button = Button(root, text="Generate graph", command=Graph_Generator) graph_button.pack(pady=30) # Display elements related to `mu` parameter label10.pack() entry6.pack() # Display elements related to `sigma` parameter label11.pack() entry7.pack() # Display elements related to `a` parameter label12.pack() entry8.pack() # Display elements related to `b` parameter label13.pack() entry9.pack() # Display elements related to `c` parameter label14.pack() entry10.pack() root.mainloop() ``` Hopefully this will help you. Best regards, Adrien Le 21/12/2022 ? 23:50, Cameron Simpson a ?crit?: > On 20Dec2022 14:14, Roberto Martin ZAMORA NEVADO wrote: >> I am developing a program for research purposes to enter from Tkinter >> values of mean, standard deviation and ranges, to graph a normal >> distribution, but it throws me an error of >> >> Traceback (most recent call last): >> ?File "C:\Program >> Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", >> line 1921, in __call__ >> ?? return self.func(*args) >> ?File "g:\Cursos\Curso B?sico de Python\Prueba 102", line 45, in >> Graph_Generator >> ?? x=np.linspace[normal(a.get()), normal(b.get()),(c.get())] >> TypeError: 'rv_continuous_frozen' object is not callable > > That suggests that `normal` is a `rv_continuous_frozen` instance. That has a bunch of methods to obtain various things. > > Looking at the docs for `scipy.stats.norm`: > https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.norm.html#scipy.stats.norm > > It looks like your line: > > ??? normal= stats.norm(mu,sigma) > > obtains one of these objects. Based on the examples there, maybe you need the distribution's `.pdf` method (probablity distribution function)? Eg in the erroring line: > > ??? x=np.linspace[normal(a.get()), normal(b.get()),(c.get())] > > you want to say `normal.pdf(a.get())` and so forth instead of just `normal`? > > The docs for `rv_continuous_frozen` are here: > https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_continuous.html#scipy.stats.rv_continuous > and it has a list of the methods about a screen or so down the page. > I do not know if you want the `.pdf()` method or one of the others. > > Cheers, > Cameron Simpson > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users