首页 > 其他分享 >习题6.3

习题6.3

时间:2024-10-22 12:22:05浏览次数:6  
标签:plt labels nx 6.3 rcParams 习题 font size

习题6.3代码

import numpy as np
import pandas as pd
import cvxpy as cp
import networkx as nx
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['Times New Roman + SimSun + WFM Sans SC']
plt.rcParams['mathtext.fontset']='stix'

Times New Roman + SimSun + WFM Sans SC

simsum宋体, times new roman -*, simhei黑体, kaiti楷体,

dengxian等线, fangsong仿宋, Microsoft Yahei微软雅黑

plt.rcParams['axes.unicode_minus']=False
plt.rcParams['figure.dpi'] = 200

plt.rcParams['figure.figsize'] = [4, 3]

plt.rcParams['font.size'] = 12

plt.rcParams['xtick.direction']='in'
plt.rcParams['ytick.direction']='in'
nodes_labels = ['v' + str(i) for i in range(1, 7)]
nodes_labels = dict(zip(range(1,7), nodes_labels))

L1 = [(1,2), (1,3), (1,4), (2,3), (2,6), (3,4), (4,5), (5,6)]
G1 = nx.Graph()
G1.add_edges_from(L1)

L2 = [(1,2,7), (1,3,3), (1,4,12), (2,3,1), (2,6,1), (3,4,8), (4,5,9), (5,6,3)]
G2 = nx.Graph()
G2.add_weighted_edges_from(L2)

L3 = [(2,1,7), (1,3,3), (4,1,12), (2,3,1), (6,2,1), (3,4,8), (5,4,9), (5,6,3)]
G3 = nx.DiGraph()
G3.add_weighted_edges_from(L3)
fig = plt.figure(dpi=400, figsize=(9,3))

ax = fig.add_subplot(131)
pos1 = nx.planar_layout(G1)
nx.draw(G1, pos1, labels=nodes_labels, with_labels='True', font_color='w', node_size=100, font_size=8)

ax1 = fig.add_subplot(132)
pos2 = nx.planar_layout(G2)
nx.draw(G2, pos2, labels=nodes_labels, with_labels='True', font_color='w', node_size=100, font_size=8)
edgelabels = nx.get_edge_attributes(G2, 'weight')
nx.draw_networkx_edge_labels(G2, pos2, edge_labels=edgelabels, font_size=6)

ax2 = fig.add_subplot(133)
pos3 = nx.planar_layout(G3)
nx.draw(G3, pos3, labels=nodes_labels, with_labels='True', font_color='w', node_size=100, font_size=8)
edgelabels = nx.get_edge_attributes(G3, 'weight')
nx.draw_networkx_edge_labels(G3, pos3, edge_labels=edgelabels, font_size=6)

fig.show()

标签:plt,labels,nx,6.3,rcParams,习题,font,size
From: https://www.cnblogs.com/DENWOSHUABAZONGSHI/p/18492312

相关文章

  • 习题6.4
    习题6.4代码importnumpyasnpimportpandasaspdimportcvxpyascpimportnetworkxasnximportmatplotlib.pyplotaspltplt.rcParams['font.sans-serif']=['TimesNewRoman+SimSun+WFMSansSC']plt.rcParams['mathtext.fontset'......
  • 习题6.1
    习题6.1代码importnumpyasnpimportpandasaspdimportcvxpyascpimportnetworkxasnximportmatplotlib.pyplotaspltplt.rcParams['font.sans-serif']=['TimesNewRoman+SimSun+WFMSansSC']plt.rcParams['mathtext.fontset'......
  • python第五章课后习题
    importnumpyasnpimportmathfromscipy.optimizeimportminimize,Boundsdeffunc(x):returnsum(math.sqrt(x[i])foriinrange(100))defcon(x):return1000-np.sum(x[i]*(101-i+1)foriinrange(100))con1={'type':'ineq','fun&#......
  • 习题6.7代码
    习题6.7代码importnumpyasnpimportpandasaspdimportcvxpyascpimportnetworkxasnximportmatplotlib.pyplotaspltdf=pd.read_excel('F:\python数学建模与算法\源程序\《Python数学建模算法与应用》程序和数据\第6章图论模型\data6.xlsx')D=df.valuesdo......
  • 刷c语言练习题9(牛客网)
    1、12345678char*getmemory(void){    charp[]= "helloworld";    returnp;}voidtest(void){    char*str=NULL;    str=getmemory(); printf(str);}请问运行Test函数会有什么样的结果?A、出错B、输出"helloworld"C、输出空......
  • python第三章课后习题
    efX(n):#差分方程的解return2*(-1)**(n+1)n_values=[0,1,2,3,4,5]forninn_values:print(f"X({n})={X(n)}")print("学号:3028")importnetworkxasnxG=nx.DiGraph()foriinrange(1,7):G.add_node(i)edges=[(1,2),(1,4......
  • 选择结构程序设计之习题
    有3个整数a,b,c,由键盘输入,输出其中最大的数//有3个整数a,b,c,由键盘输入,输出其中最大的数#include<stdio.h>intmain(void){ inta,b,c; scanf("a=%db=%dc=%d",&a,&b,&c); if(a>b) { inttemp=a; a=b; b=temp; }//a<b if(a&g......
  • 六,数组笔记及相关练习题大全
    Java编程基础:数组详解在Java编程中,数组是一块连续固定大小的内存空间,用于存储相同类型的多个元素。数组提供了索引的概念,允许通过索引访问和操作数组中的元素。本文将详细探讨Java中数组的定义、初始化、使用和示例。数组的定义和初始化数组在定义时需要指定数据类型和数组名。......
  • 移情别恋c++ ദ്ദി˶ー̀֊ー́ ) ——13.map&&set(无习题)
    C++中的set和map容器详细总结1.概述C++标准模板库(STL)提供了多种关联容器,用于管理键值对和集合的数据。其中,set和map是最常用的两种关联容器。set用于存储唯一的元素集合,而map则用于存储键值对,其中每个键都是唯一的。它们都使用红黑树(自平衡二叉搜索树)作为底......
  • 数学建模与数学实验习题4.4.2答案matlab
    炼油厂将ABC三种原油加工成甲乙丙三种汽油,一桶原油加工成一桶汽油的费用为4元,每天至多能加工汽油14000桶,原油的买入价,买入量,辛烷值,硫的含量以及汽油的卖出价,需求量辛烷值和硫含量由下表给出,如何安排生产计划使利润最大一般来说,做广告可以增加销售,估计一天向一种汽油投......