我用matplotlib搜索如何用尽可能少的指令绘制一些东西,但我在文档中找不到任何帮助.
我想绘制以下内容:
怎么做?
我在python中有一个包含3维数据的元组列表,其中每个元组的形式为:(x,y,z,data_value),即我在每个(x,y,z)坐标处都有数据值.我想制作一个3D离散热图,其中颜色代表我的元组列表中data_values的值.在这里,我举一个这样的2D数据集热图的例子,其中我有一个(x,y,data_value)元组的列表:
import matplotlib.pyplot as plt
from matplotlib import colors
import numpy as np
from random import randint
# x and y coordinates
x = np.array(range(10))
y = np.array(range(10,15))
data = np.zeros((len(y),len(x)))
# Generate some discrete data (1, 2 or 3) for each (x, y) pair
for i,yy in enumerate(y):
for j, xx in enumerate(x):
data[i,j] = randint(1,3)
# Map 1, 2 and 3 to 'Red', 'Green' qnd 'Blue', respectively
colormap = colors.ListedColormap(['Red', 'Green', 'Blue'])
colorbar_ticklabels = ['1', '2', '3']
# …
Run Code Online (Sandbox Code Playgroud) 在Python中,给定一个N_1 x N_2 x N_3
包含0或1 的矩阵,我将寻找一种以3D形式将数据显示为N_1 x N_2 x N_3
体积为1s 的体积像素(体素)的方法。
例如,如果1s的坐标为[[1, 1, 1], [4, 1, 2], [3, 4, 1]]
,则所需的输出将如下所示
看来mplot3D
matplotlib 的模块可以实现这一目标,但我还没有找到这种绘图的任何示例。有人知道解决此问题的简单解决方案吗?
在此先感谢您的帮助。
我正在尝试使用 matplotlib 绘制不同大小的长方体,这样:旋转后,长方体不会以非物理方式在视觉上重叠,立方体具有不同的颜色并在它们周围绘制一个框。
我已经阅读了几篇引用类似问题的博客文章和 stackoverflow 页面,但总是略有不同;没有一个对我有用。克服重叠问题的最简单方法是使用体素(如https://matplotlib.org/api/_as_gen/mpl_toolkits.mplot3d.axes3d.Axes3D.html?highlight=voxel#mpl_toolkits.mplot3d.axes3d.Axes3D.voxels ),但这些不允许我在它们周围画框。在 matplotlib 中执行此操作的最简单方法是什么?
下图显示了我在左边的东西,以及我想要的东西在右边。
编辑:我研究了几种可以产生预期效果的方法,其中主要的方法是:
前者似乎更容易执行,但我仍然很难过。
我正在尝试使用 matplotlib绘制 3d笛卡尔坐标系,将原点居中,用箭头绘制3 个方向,类似这样的东西
我已经根据这篇文章用这个代码绘制了一个二维版本
def build_cartesian_plane(max_quadrant_range):
""" The quadrant range controls the range of the quadrants"""
l = []
zeros = []
f, ax = plt.subplots(figsize=(5,5))
plt.grid(True, color='grey', zorder=0,alpha=.5)
head_width = float(0.05) * max_quadrant_range
head_length = float(0.1) * max_quadrant_range
ax.arrow(0, 0, max_quadrant_range, 0, head_width=head_width, head_length=head_length, fc='k', ec='k',zorder=100)
ax.arrow(0, 0, 0, max_quadrant_range, head_width=head_width, head_length=head_length, fc='k', ec='k', zorder=100)
counter_dash_width = max_quadrant_range * 0.02
dividers = [0,.1,.2,.3,.4, .5, .6, .7, .8, .9, 1]
ax.spines['top'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
for …
Run Code Online (Sandbox Code Playgroud)