sagemath-list_plot()改变点的大小

在SageMath中使用list_plot()绘制散点图时,默认点的大小较小。不同于Python的matplotlib,list_plot()不接受markersize参数。调节点大小需使用'size'或'pointsize'参数。例如,设置size=30或pointsize=50可以增大点的大小。参照SageMath手册,可以找到更多关于list_plot()函数的参数设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

sagemath中,使用list_plot()函数画散点图时,默认情况下的点的大小较小。

示例: 

a=range(10)
b=(random()*20 for _ in range(10))
array=[]
plot1 = list_plot(zip(a,b),color=(0,.5,1),marker='o',ticks=[range(10),range(20)],legend_label='Original Data Points')
plot1.axes_labels(['x coordinate ','y coordinate'])
plot1.axes_labels_size(1.2)
plot1.legend(True)
plot1.show(frame=True)

对比在python的matplotlib中,是通过markersize调节marker的大小:参考1 参考2

但在sagemath的list_plot中,不能用该参数调节。

如果将 上例中的函数改为:

plot1 = list_plot(zip(a,b),color=(0,.5,1),marker='o',ticks=[range(10),range(20)],legend_label='Original Data Points',markersize=50)

这里会提示:

verbose 0 (163: primitive.py, options) WARNING: Ignoring option 'markersize'=50
verbose 0 (163: primitive.py, options) 
The allowed options for Point set defined by 10 point(s) are:
    alpha          How transparent the point is.                               
    faceted        If True color the edge of the point. (only for 2D plots)    
    hue            The color given as a hue.                                   
    legend_color   The color of the legend text                                
    legend_label   The label for this item in the legend.                      
    marker         the marker symbol for 2D plots only (see documentation of plot() for details)
    markeredgecolorthe color of the marker edge (only for 2D plots)            
    rgbcolor       The color as an RGB tuple.                                  
    size           How big the point is (i.e., area in points^2=(1/72 inch)^2).
    zorder         The layer level in which to draw                            

verbose 0 (163: primitive.py, options) WARNING: Ignoring option 'markersize'=50
verbose 0 (163: primitive.py, options) 
The allowed options for Point set defined by 10 point(s) are:
    alpha          How transparent the point is.                               
    faceted        If True color the edge of the point. (only for 2D plots)    
    hue            The color given as a hue.                                   
    legend_color   The color of the legend text                                
    legend_label   The label for this item in the legend.                      
    marker         the marker symbol for 2D plots only (see documentation of plot() for details)
    markeredgecolorthe color of the marker edge (only for 2D plots)            
    rgbcolor       The color as an RGB tuple.                                  
    size           How big the point is (i.e., area in points^2=(1/72 inch)^2).
    zorder         The layer level in which to draw                            

verbose 0 (163: primitive.py, options) WARNING: Ignoring option 'markersize'=50
verbose 0 (163: primitive.py, options) 
The allowed options for Point set defined by 10 point(s) are:
    alpha          How transparent the point is.                               
    faceted        If True color the edge of the point. (only for 2D plots)    
    hue            The color given as a hue.                                   
    legend_color   The color of the legend text                                
    legend_label   The label for this item in the legend.                      
    marker         the marker symbol for 2D plots only (see documentation of plot() for details)
    markeredgecolorthe color of the marker edge (only for 2D plots)            
    rgbcolor       The color as an RGB tuple.                                  
    size           How big the point is (i.e., area in points^2=(1/72 inch)^2).
    zorder         The layer level in which to draw  

 可以看到这里提示markersize=50的设置被忽略,给出的10个参数中调节大小的是size参数,所以,将list_plot()函数中的参数设置为size,设置size=30:

a=range(10)
b=(random()*20 for _ in range(10))
array=[]
plot1 = list_plot(zip(a,b),color=(0,.5,1),marker='o',ticks=[range(10),range(20)],legend_label='Original Data Points',size=30)
plot1.axes_labels(['x coordinate ','y coordinate'])
plot1.axes_labels_size(1.2)
plot1.legend(True)
plot1.show(frame=True)

显示画出的点增大为30:

根据 sage手册 page:84的list_plot参数设置,可参考plot()的关键字的设置。

help(plot)

 显示关于size的部分:

The algorithm used to insert extra points is actually pretty
    simple. On the picture drawn by the lines below::
    
        sage: p = plot(x^2, (-0.5, 1.4)) + line([(0,0), (1,1)], color='green')
        sage: p += line([(0.5, 0.5), (0.5, 0.5^2)], color='purple')
        sage: p += point(((0, 0), (0.5, 0.5), (0.5, 0.5^2), (1, 1)), color='red', pointsize=20)
        sage: p += text('A', (-0.05, 0.1), color='red')
        sage: p += text('B', (1.01, 1.1), color='red')
        sage: p += text('C', (0.48, 0.57), color='red')
        sage: p += text('D', (0.53, 0.18), color='red')
        sage: p.show(axes=False, xmin=-0.5, xmax=1.4, ymin=0, ymax=2)

 

也可通过pointsize调节,将pointsize设置为pointsize=50:

a=range(10)
b=(random()*20 for _ in range(10))
array=[]
plot1 = list_plot(zip(a,b),color=(0,.5,1),marker='o',ticks=[range(10),range(20)],legend_label='Original Data Points',pointsize=50)
plot1.axes_labels(['x coordinate ','y coordinate'])
plot1.axes_labels_size(1.2)
plot1.legend(True)
plot1.show(frame=True)

设置pointsize=50的效果:

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值