How to connect markers of probability plot with lines

王林
Release: 2024-02-06 08:51:04
forward
739 people have browsed it

How to connect markers of probability plot with lines

Question content

I am using python version 3.11.1 and I created a probability plot using matplotlib.pyplot using the code below. I want to automatically connect markers with a line, but probplot's documentation doesn't seem to have an option to connect them.

This is my sample code:

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

nsample = 20
np.random.seed(100)

fig = plt.figure()
ax = fig.add_subplot(111)
x = stats.t.rvs(3, size=nsample)
res = stats.probplot(x, plot=plt)

ax.get_lines()[0].set_markeredgecolor('b')
ax.get_lines()[0].set_markerfacecolor('b')

plt.show()
Copy after login

This is the picture generated by the sample code:

Here is the plot with markers connected to the "Hand Draw" line to show you everything I need the code to do automatically.


Correct answer


Since the result actually seems to give the coordinates of the point, you can simply use:

ax.plot(*res[0])
Copy after login

...or better yet, just create the entire plot yourself and then you have full control over how to style it:

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

nsample = 20
np.random.seed(100)

x = stats.t.rvs(3, size=nsample)
(res_x, res_y), (slope, intercept, r) = stats.probplot(x)

f, ax = plt.subplots()
ax.plot(res_x, res_y, c="b", marker="o")
ax.plot(res_x, intercept + slope * res_x, c="r")
Copy after login

The above is the detailed content of How to connect markers of probability plot with lines. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template