我正在尝试linestyle=":"在networkx边缘绘制轮廓()。我似乎无法弄清楚如何对matplotlib patch对象执行此操作? 现在有没有人如何操纵这些patch物体以在这些“边缘”上绘制轮廓?如果无法做到这一点,是否有人知道如何获取行数据以ax.plot(x,y,linestyle=":")单独使用?
import networkx as nx
import numpy as np
from collections import *
# Graph data
G = {'y1': OrderedDict([('y2', OrderedDict([('weight', 0.8688325076457851)])), (1, OrderedDict([('weight', 0.13116749235421485)]))]), 'y2': OrderedDict([('y3', OrderedDict([('weight', 0.29660515972204304)])), ('y4', OrderedDict([('weight', 0.703394840277957)]))]), 'y3': OrderedDict([(4, OrderedDict([('weight', 0.2858185316736193)])), ('y5', OrderedDict([('weight', 0.7141814683263807)]))]), 4: OrderedDict(), 'input': OrderedDict([('y1', OrderedDict([('weight', 1.0)]))]), 'y4': OrderedDict([(3, OrderedDict([('weight', 0.27847763084646443)])), (5, OrderedDict([('weight', 0.7215223691535356)]))]), 3: OrderedDict(), 5: OrderedDict(), 'y5': OrderedDict([(6, OrderedDict([('weight', 0.5733512797415756)])), (2, OrderedDict([('weight', 0.4266487202584244)]))]), 6: OrderedDict(), 1: OrderedDict(), …Run Code Online (Sandbox Code Playgroud) 我想缩放markersize的matplotlib.pyplot.Axes.scatter基于在x/y轴的点的数量曲线图.
import matplotlib.pyplot as plt
import numpy as np
vmin = 1
vmax = 11
x = np.random.randint(vmin, vmax, 5)
y = np.random.randint(vmin, vmax, 5)
fig, ax = plt.subplots()
for v in np.arange(vmin, vmax):
ax.axvline(v - 0.5)
ax.axvline(v + 0.5)
ax.axhline(v - 0.5)
ax.axhline(v + 0.5)
ax.set_xlim(vmin - 0.5, vmax + 0.5)
ax.set_ylim(vmin - 0.5, vmax + 0.5)
ax.scatter(x, y)
ax.set_aspect(1)
plt.show()
Run Code Online (Sandbox Code Playgroud)
ax始终使用相等的纵横比,两个轴具有相同的lim值.
该markersize两地块留给默认,即markersize=6. …
我试图找出如何以数据单位绘制宽度的线条.例如,在下面的代码片段中,我希望宽度为80的线的水平部分始终从y = -40延伸到y = + 40标记,即使坐标系的限制也保持这种状态更改.有没有办法用matplotlib中的Line2D对象来实现这个目的?任何其他方式获得类似的效果?
from pylab import figure, gca, Line2D
figure()
ax = gca()
ax.set_xlim(-50, 50)
ax.set_ylim(-75, 75)
ax.add_line(Line2D([-50, 0, 50], [-50, 0, 0], linewidth=80))
ax.grid()
Run Code Online (Sandbox Code Playgroud)

我从切换matplotlib到plotly主要是绘制在2D / 3D流畅的动画。我想绘制由多个圆/球组成的机器人的运动。
机器人的不同身体部位具有不同的大小,圆圈需要准确地表示出来。是否有办法plotly来指定数据单元标记的大小?例如,我想绘制一个5m x 5m(x5m)的截面,其中半径为0.1m的圆/球沿着不同的轨迹运动。
在matplotlib中,我知道两种选择。一种是使用补丁(matplotlib.patches.Circle)。第二种方法是绘制点并通过考虑dpi正确缩放其marker_size(请参阅matplotlib的此问题的答案)。
A)是否可以对图形进行3D动画处理?
要么
B)有没有办法以数据单位指定标记的大小或正确缩放sizeref属性?
# Point with radius 2 (approx.)
from plotly.offline import plot
import plotly.graph_objs as go
trace = go.Scatter(x=[4], y=[4],
mode='markers',
marker={'size': 260, 'sizeref': 1}) # ???
layout = dict(yaxis=dict(range=[0, 10]),
xaxis=dict(range=[0, 10]))
fig = dict(data=[trace], layout=layout)
plot(fig, image_height=1000, image_width=1000)
Run Code Online (Sandbox Code Playgroud)
缩放marker_size的问题是,只有当您不放大或缩小图像时,图像才是正确的,因为marker_size保持恒定。因此,更干净的方法是直接以数据单位指定圆圈的大小。
如果在 Matplotlib 中设置线宽,则必须以磅为单位给出线宽。就我而言,我有两个圆,半径均为 R,我想用一条线将它们连接起来。我希望这条线是 2*R 宽以获得棒状。但是当我说myLines[i].set_linewidth(2*R)这会使线条始终具有特定的粗细,无论我放大了多少。
有没有办法使线条具有特定的粗细,而不是基于像素或点的数量,而是随轴缩放?如何使我的线条与圆圈的直径具有相同的宽度?
我希望我能很好地解释自己,我期待着答案。
是否可以将matplotlib路径的线宽与图形缩放/比例级别联系起来?
我正在绘制一张地图,其中matplotlib路径(带有贝塞尔曲线)在地图上绘制道路.在放大时,我希望放大路径的宽度.
在附加脚本中,多边形近似可以正确缩放,但路径(红线)不能缩放(宽度).
是否可以将线宽与某种比例转换联系起来并通过回调重绘?
import matplotlib.pyplot as plt
from matplotlib.path import Path
import matplotlib.patches as patches
import numpy as np
def main():
ax = plt.subplot(111)
verts = np.array([ (0., 0.), (0.5, .5), (1., 0.8), (0.8, 0.)])
codes = np.array([Path.MOVETO, Path.CURVE4, Path.CURVE4, Path.LINETO ])
# Can this curve have zoomable width
path = Path(verts, codes)
patch = patches.PathPatch(path, fc='none', color='r', lw=4, zorder=3)
ax.add_patch(patch)
ax.plot(verts[:,0], verts[:,1], 'o--', lw=2, color='k', zorder=2)
# these will be polygonal approx that will have proper zoom
v=np.array([]).reshape((-1,2)) …Run Code Online (Sandbox Code Playgroud) 在 xy 图表上探索具有多个点的数据集时,我可以调整 alpha 和/或标记大小,以快速直观地了解这些点聚集最密集的位置。但是,当我放大或使窗口变大时,需要不同的 alpha 和/或标记大小来提供相同的视觉印象。
当我放大窗口或放大数据时,如何增加 alpha 值和/或标记大小?我在想,如果我将窗口面积加倍,我可以将标记大小加倍,和/或取 alpha 的平方根;和缩放相反。
请注意,所有点都具有相同的大小和 alpha。理想情况下,该解决方案适用于 plot(),但如果它只能使用 scatter() 完成,那也会有帮助。
matplotlib ×6
python ×6
line ×2
plot ×2
networkx ×1
pandas ×1
plotly ×1
python-3.x ×1
scatter ×1