此问题已在此处有答案:
How does plt.gca work internally(2个答案)
How to change the plot line color from blue to black(3个答案)
上个月关门了。
我有以下代码:
import numpy as np
from fitter import Fitter
from matplotlib import pyplot as plt
randomData = np.random.normal(0, 1, 1000)
def plotOfFittedDistributions(data):
f = Fitter(data, distributions=['gamma', "norm", 'invgauss'], timeout=100)
f.fit()
f.hist()
f.plot_pdf()
ax = plt.gcf()
return ax
a = plotOfFittedDistributions(data=randomData)
a
可以看出,我使用plt.gcf()
访问了当前图形。是否可以在使用plt.gcf()
访问后更改绘图的颜色?因此,我想在创建后访问具有多个绘图的单个图形,然后更改其颜色。
目前我有这个,它改变了颜色,但非常'丑陋'的代码:
def colorShift(fig, newColor):
tracker = []
for i in range(0, len(fig.gca().get_children())):
if type(fig.gca().get_children()[i]) == matplotlib.patches.Rectangle:
tracker.append(i)
for i in tracker[:len(tracker)-1]:
fig.gca().get_children()[i].set_color(newColor)
1条答案
按热度按时间up9lanfz1#
我找到了答案: