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()
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.
Since the result actually seems to give the coordinates of the point, you can simply use:
ax.plot(*res[0])
...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")
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!