Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >matplotlib pyplot -尺寸与数据成比例的子图

matplotlib pyplot -尺寸与数据成比例的子图
EN

Stack Overflow用户
提问于 2021-08-03 01:04:22
回答 1查看 69关注 0票数 0

我想创建一个带有子图的图形,其中每个子图的大小与它包含的数据成比例。例如:

代码语言:javascript
运行
AI代码解释
复制
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']:
    venn2(subsets = data_dict[x], set_labels=('A', 'B'), ax=axes[i])
    i += 1

我想通过每个维恩图(A+B+intersect)中的数字之和来缩放每个子图的大小。我该怎么做呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-03 01:52:05

我刚开始在matplotlib中绘制维恩图,但我认为如果你在gridspec_kw中设置宽度比例是可能的。我总结来自字典数据的数据,确定组成比例,并将其指定为比例。

代码语言:javascript
运行
AI代码解释
复制
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)}
ratios = [sum(v) for v in data_dict.values()]
norm = [n / sum(ratios) for n in ratios]

figure, axes = plt.subplots(1, 3, gridspec_kw=dict(width_ratios=norm))
i = 0
for x in ['foo','bar','baz']:
    venn2(subsets = data_dict[x], set_labels=('A', 'B'), ax=axes[i])
    i += 1

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68633192

复制
相关文章
理解matplotlib、pylab与pyplot之间的关系
这些模块其实功能都相同,程序运行的时候都在运行相同的code,不同的是导入模块的方式不同。
老潘
2018/06/21
1.8K0
理解matplotlib、pylab与pyplot之间的关系
Matplotlib Pyplot教程
最近自己经常遇到matplotlib的OO API和pyplot包混乱不分的情况,所以抽时间好好把matplotlib的文档读了一下,下面是大概的翻译和总结。很多基础的东西还是要系统地掌握牢固哇~~另外一篇翻译是
曲奇
2021/12/14
7370
Matplotlib Pyplot教程
matplotlib - Pyplot 教程
matplotlib.pyplot 是命令样式函数的集合,使matplotlib像MATLAB一样工作。 每个pyplot函数对图形进行一些更改:例如,创建图形,在图形中创建绘图区域,在绘图区域中绘制一些线条,用标签装饰图形等。
量子态的沐子呓
2019/12/25
1.8K0
matplotlib - Pyplot 教程
Python数据分析(中英对照)·Introduction to Matplotlib and Pyplot-Matplotlib 和 Pyplot 介绍
Matplotlib is a Python plotting library that produces publication-quality figures. Matplotlib是一个Python绘图库,用于生成出版物质量的图形。 It can be used both in Python scripts and when using Python’s interactive mode. 它既可以在Python脚本中使用,也可以在使用Python的交互模式时使用。 Matplotlib is a very large library, and getting to know it well takes time. Matplotlib是一个非常大的库,了解它需要时间。 But often we don’t need the full matplotlib library in our programs,and this is where Pyplot comes in handy. 但是我们的程序中通常不需要完整的matplotlib库,这就是Pyplot的用武之地。 Pyplot is a collection of functions that make matplotlib work like Matlab,which you may be familiar with. Pyplot是一组函数,使matplotlib像Matlab一样工作,您可能熟悉这些函数。 Pyplot is especially useful for interactive work,for example, when you’d like to explore a dataset or visually examine your simulation results. Pyplot对于交互式工作尤其有用,例如,当您希望浏览数据集或直观地检查模拟结果时。 We’ll be using Pyplot in all our data visualizations. 我们将在所有数据可视化中使用Pyplot。 Pyplot provides what is sometimes called a state machine interface to matplotlib library. Pyplot为matplotlib库提供了有时称为状态机的接口。 You can loosely think of it as a process where you create figures one at a time,and all commands affect the current figure and the current plot. 您可以粗略地将其视为一个一次创建一个地物的过程,所有命令都会影响当前地物和当前绘图。 We will mostly use NumPy arrays for storing the data that we’d like to plot, but we’ll occasionally use other types of data objects such as built-in lists. 我们将主要使用NumPy数组来存储要绘制的数据,但偶尔也会使用其他类型的数据对象,如内置列表。 As you may have realized, saying matplotlib.pyplot is kind of a mouthful, and it’s a lot to type too. 正如您可能已经意识到的那样,说matplotlib.pyplot有点口齿不清,而且打字也很费劲。 That’s why virtually everyone who uses the library imports it as plt, which is a lot shorter. 这就是为什么几乎所有使用该库的人都将其作为plt导入,而plt要短得多。 So to import the library, we will type the following– import matplotlib.pyplot as plt. 因此,要导入库,我们将键入以下内容–import matplotlib.pyplot as plt。 Now we are ready to start our plotting. 现在我们准备开始我们的阴谋。 A basis but very useful command is the plt plot function, which can be used to plot lines and markers. plt plot函数是一个基本
数媒派
2022/12/01
5100
matplotlib.pyplot.gca
Get the current Axes instance on the current figure matching the given keyword args, or create one.
狼啸风云
2019/09/29
7290
matplotlib.pyplot中的hist函数
首先构造数据,这里注意构造的是一维数组可以使用pandas中的Series,如果是二维数组使用DataFrame。
周小董
2019/03/25
4.6K0
matplotlib.pyplot中的hist函数
python 使用 matplotlib.pyplot来画柱状图和饼图
导入包 import matplotlib.pyplot as plt 柱状图 最简柱状图 # 显示高度 def autolabel(rects): for rect in rects: height = rect.get_height() plt.text(rect.get_x()+rect.get_width()/2.- 0.2, 1.03*height, '%s' % int(height)) name_list = ['A', 'B', 'C', 'D',
范中豪
2019/09/10
1.6K0
python 使用 matplotlib.pyplot来画柱状图和饼图
数据可视化-Matplotlib使用子图绘制数据
今天我们将学习如何在Matplotlib中使用子图。使用子图,以便我们可以以更面向对象的方式使用Matplotlib。我们将学习如何使用子图来绘制我们在之前的文章中关于开发语言工资的数据图表,然后我们将学习如何使用子图在一个图上创建多个图。让我们开始吧...
XXXX-user
2019/08/09
1.3K0
matplotlib基础手册:pyplot手册
matplotlib.pyplot 是一个函数集合,使 matplotlib 能够像 MATLAB 一样进行绘图。每一个 pyplot 函数都会改变 figure,比如创建figure,在figure中创建绘图区域,在绘图区域绘制线条,添加 labels 等。matplotlib.pyplot 的函数调用会记住当前的状态,从而更新 figure 和 绘图区域。而且 matplotlib.pyplot 是直接在当前 axes 进行绘图。
bugsuse
2020/04/21
2.8K0
matplotlib基础手册:pyplot手册
航摄比例尺、成图比例尺、地面分辨率与航摄设计用图比例尺
根据武汉大学《摄影测量学》中的定义:航摄比例尺是航摄影像上一线段l与相应地面线段L的水平距离之比:
charlee44
2020/07/21
4.4K0
航摄比例尺、成图比例尺、地面分辨率与航摄设计用图比例尺
Matplotlib 中文用户指南 3.1 pyplot 教程
matplotlib.pyplot是一个命令风格函数的集合,使matplotlib的机制更像 MATLAB。 每个绘图函数对图形进行一些更改:例如,创建图形,在图形中创建绘图区域,在绘图区域绘制一些线条,使用标签装饰绘图等。在matplotlib.pyplot中,各种状态跨函数调用保存,以便跟踪诸如当前图形和绘图区域之类的东西,并且绘图函数始终指向当前轴域(请注意,这里和文档中的大多数位置中的『轴域』(axes)是指图形的一部分(两条坐标轴围成的区域),而不是指代多于一个轴的严格数学术语)。
ApacheCN_飞龙
2022/12/01
1.7K0
Matplotlib 中文用户指南 3.1 pyplot 教程
import matplotlib.pyplot as plt报错
在使用intellij idea时,当通过如下方式使用时,matplotlib.pyplot导入报错,使用方法如下:
程序新视界
2023/07/09
4110
Python 绘图包 Matplotlib Pyplot 教程
matplotlib.pyplot 是命令风格函数的集合,使 Matplotlib 像 MATLAB 一样工作。每个 Pyplot 函数对图形做一些修改,例如:创建一个图形,在图形中创建一个绘图区域,在绘图区域中回值一些线条,用标签装饰图形等等。
用户7886150
2020/12/25
1.1K0
Matplotlib可视化Pyplot Tutorial
MATLAB, and pyplot, have the concept of the current figure and the current axes. All plotting commands apply to the current axes. The function gca() returns the current axes (a matplotlib.axes.Axes instance), and gcf() returns the current figure (matplotlib.figure.Figure instance).
用户2183996
2018/06/28
6580
Matplotlib子图划分——非均匀绘图
本节主要探讨matplotlib子图的非均匀划分,并在文末补充了axes对象的常用属性。
python数据可视化之路
2023/02/23
1.5K0
Matplotlib子图划分——非均匀绘图
python怎么安装matplotlib.pyplot_python安装matplotlib模块
1、打开Anaconda Prompt ,输入 pip install matplotlib
全栈程序员站长
2022/09/25
4.7K0
Python学习:matplotlib.pyplot图像绘制
1.首先看第一个函数matplotlib.pyplot.subplot,这个函数是为了在一张图里放置多个子图。
烤粽子
2021/07/07
7780
Python学习:matplotlib.pyplot图像绘制
点击加载更多

相似问题

奇数子图的Matplotlib/Pyplot共享轴

10

matplotlib.pyplot from函数中的子图

10

强制pyplot子图使用相同的y轴比例

10

matplotlib.pyplot:创建存储地块的子图

10

Matplotlib子图:图例和轴比例

17
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档