plotly绘制简单图形<4>--饼形图

plotly绘制简单图形<1>--散点图折线图

plotly绘制简单图形<2>--条形图

plotly绘制简单图形<3>--设置按钮

本次说一下饼形图:

目录

1、简单饼形图

2、设置修饰

3、甜圈图


1、简单饼形图

import  plotly.plotly as py
import plotly.graph_objs as go

labels = ['A','B','C','D']
values = [4500,2500,1053,500]

trace = go.Pie(labels=labels, values=values)

py.iplot([trace], filename='basic_pie_chart')

2、设置修饰

import plotly.plotly as py
import plotly.graph_objs as go

labels = ['A','B','C','D']
values = [4500,2500,1053,500]
colors = ['#FEBFB3', '#E1396C', '#96D38C', '#D0F9B1']#自定义颜色

trace = go.Pie(labels=labels, values=values,
               hoverinfo='label+percent', textinfo='value', 
               textfont=dict(size=20),#数据标签字体大小
               marker=dict(colors=colors, 
                           line=dict(color='#000000', width=3)))#设置线框颜色和粗细

py.iplot([trace], filename='styled_pie_chart')

3、甜圈图

import plotly.plotly as py
import plotly.graph_objs as go

fig = {
  "data": [
    {
      "values": [16, 15, 12, 6, 5, 4],
      "labels": ['A','B','C','D','E','F'],
      "domain": {"x": [0, 1]},#图形区域位置(绘制两个或者多个子图需要用到)
      "name": "GHG Emissions",
      "hoverinfo":"label+percent+name",
      "hole": .4,#内圈大小
      "type": "pie"
    }],
  "layout": {
        "title":"图例",
        "annotations": [
            {
                "font": {
                    "size": 20
                },
                "showarrow": False,
                "text": "GHG",
                "x": 0.5,
                "y": 0.5#内圈文本位置与上面图形位置对应
            }
        ]
    }
}
py.iplot(fig, filename='donut')

PS:右边的图例,可以根据需要进行设置是否显示,点击一下相应变量变成灰色,左边图形会将其剔除

画出GraphItem类的UML类图: #ifndef GRAPHITEM_H #define GRAPHITEM_H #include <QGraphicsItem> #include <QVector> #include <QPointF> #include <QtMath> #include <QTimer> #include <QPaintEvent> #include <QPushButton> #include "mainwindow.h" #include <QObject> class MainWindow; // 前向声明 class GraphItem : public QGraphicsItem { public: //构造函数,接受带权无向图临界矩阵adjMatrix和一个parent GraphItem(const QVector<QVector<int>> &adjMatrix, const QVector<int> &shortestPath, QGraphicsItem *parent = nullptr); //纯虚函数,在.cpp中重新编写以实现图形项的边界框绘制 QRectF boundingRect() const override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; QVector<QPointF> m_nodePositions;//存储节点的位置信息 QVector<int> m_shortestPath; // 最短路径 QVector<int> m_userCity; QVector<int> m_userSchool; bool m_drawArrow; // 是否需要绘制箭头 bool m_draw1; bool m_draw2; bool m_draw3; private: MainWindow * m_mainWindow; // 指向MainWindow对象的指针 QVector<QVector<int>> m_adjMatrix;//存储带权无向图的邻接矩阵 QPointF startPoint; QPointF endPoint; QPainter * m_painter; QPainter * m_drawNodes; void initializeNodePositions();//初始化节点位置信息 void drawEdges(QPainter * painter);//用于绘制边 void drawNodes1(QPainter * painter);//用于绘制节点 void drawNodes2(QPainter * painter);//用于绘制节点 void drawNodes3(QPainter * painter);//用于绘制节点 void paintArrow(QPainter * painter); }; #endif // GRAPHITEM_H
07-14
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Andy_shenzl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值