我想用下面的代码来产生4个相同大小的子图,x轴和y轴的大小之间的公共纵横比由我设置。参考下面的例子,我希望所有的子图看起来都和第一个完全一样(左上角)。现在的错误是y轴的大小与其最大值相关。这是我想要避免的行为。
import matplotlib.pyplot as plt
import numpy as np
def main():
fig = plt.figure(1, [5.5, 3])
for i in range(1,5):
fig.add_subplot(221+i-1, adjustable='box', aspect=1)
我想要创建一个图形,其中的子图是动态地添加到一个for-循环中。应该可以定义每个子图的宽度和高度(以厘米为单位),也就是说,添加的子图越多,所需的图形就越大,以便为“传入”子图腾出空间。
在我的例子中,子图应该是按行排列的,这样在y维中图必须变得更大。我遇到了这个,它可能会朝着正确的方向前进?也许也能解决这个问题?
我尝试了第一篇文章中描述的代码,但这不能解决我的问题(它设置了最终的图形大小,但是每个子图中添加的子图越多,每个子图得到的子图就越小,如本例所示):
import matplotlib.pyplot as plt
# set number of plots
n_subplots
我想创建一个带有子图的图形,其中每个子图的大小与它包含的数据成比例。例如: from matplotlib import pyplot as plt
from matplotlib_venn import venn2
data_dict = {'foo': (10,7,5), 'bar': (2,6,3), 'baz': (22,17,12)}
figure, axes = plt.subplots(1, 3)
i = 0
for x in ['foo','bar','baz']:
ven
我制作了一系列的图,每个图的值范围都不同,所以每个图的比例都不同。我试图保持比例一致(从0到130000),所以我设置了midpoint=6500,但它似乎不起作用。
for (i in 2016:2018){
for (m in 1:12){
yourfilename=paste(i,m,".jpg",sep="")
jpeg(file=yourfilename, width =800, height = 700)
product_by_month<- data_all%>%
fi
我正在实现一个朴素的贝叶斯分类器。
下面的图显示了我的分类边界:
我想让轴按图形等比例缩放,因为我认为这可以帮助我更好地理解正在发生的事情。然而,我还没有找到任何方法来做到这一点。这个图是由一个不是我写的函数生成的:
%matplotlib inline
plotBoundary(BayesClassifier(), dataset='iris',split=0.7)
# ## Plotting the decision boundary
#
# This is some code that you can use for plotting the decision
我用水瓶在网页上绘制了从熊猫数据中生成的matplotlib子图。这是相关代码。
import matplotlib.pyplot as plt
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from io import BytesIO,StringIO
plt.style.use('ggplot')
plt.rcParams['xtick.color']='k'
plt.rcParams['xtick.labelsize']
我最近发现了函数子图,这似乎是一种比子图更优雅的设置多个子图的方法。但是,我似乎无法更改每个子图的轴的属性。
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as npx = np.linspace(0, 20, 100)
fig, axes = plt.subplots(nrows=2)
for i in range(10):
axes[0].plot(x, i * (x - 10)**2)
plt.ylabel('plot 1')
for i in range(
使用Pandas在I-Python Notebook中绘图,我有几个绘图,因为Matplotlib决定Y轴,所以它设置它们不同,我们需要使用相同的范围比较数据。我已经在上尝试了几个变体:(我假设我需要对每个图应用限制。但既然我不能让它工作...从Matplotlib文档看,我似乎需要设置ylim,但我不能确定这样做的语法。
df2250.plot(); plt.ylim((100000,500000)) <<<< if I insert the ; I get int not callable and if I leave it out I get invalid s
如何确定子图(AxesSubplot)是否为空?我想停用空子图的空轴,并删除完全空行。
例如,在此图中,仅填充了两个子图,其余的子图为空。
import matplotlib.pyplot as plt
# create figure wit 3 rows and 7 cols; don't squeeze is it one list
fig, axes = plt.subplots(3, 7, squeeze=False)
x = [1,2]
y = [3,4]
# plot stuff only in two SubAxes; other axes are empty
axe