• 0 Oy - 0 Ortalama
  • 1
  • 2
  • 3
  • 4
  • 5
python ile pdf oluşturma

 
#1

bi yerden buldum paylaşmak istedim


#!/usr/bin/python
# -*- coding: latin-1 -*-
from __future__ import print_function
import fitz
import sys

#==============================================================================
# Pie Chart program - semi circle version
#==============================================================================
from fitz.utils import getColor        # for getting RGB colors by name
doc = fitz.open()                      # new empty PDF
doc.insertPage()                       # creates an ISO-A4 portrait page
page = doc[-1]                         # this is the page
# title of the page
title = "Sitzverteilung nach der Bundestagswahl 2013"
# pie chart center and point of 1st data pie
center = fitz.Point(200, 250)
point  = fitz.Point(100, 250)          # will cycle through table data
# this is the radius
radius = abs(point - center)

blue = getColor("blue")                # we need some colors
white = getColor("white")

lineheight = 20                        # legend line height
ts_v  = 150                            # vertical start of legend block
ts_h  = center.x + radius + 50         # horizontal coord of legend block

# these are the data to visualize:
# number of seats of political parties in German parliament since 2013
table  = (       # seats, party color & name
         (64, "violetred", "Die Linke"),
         (193, "red", "SPD"),
         (63, "green", "Die Grünen"),
         (253, "black", "CDU"),
         (56, "dodgerblue", "CSU"),
         (1, "gray", "fraktionslos"),
        )

seats = float(sum([c[0] for c in table]))   # total seats
stitle = "Bundestagssitze insgesamt: %i" % (seats,)

page.insertText(fitz.Point(72, 72),title, fontsize = 14, color = blue)

page.drawLine(fitz.Point(72, 80), fitz.Point(550, 80), color = blue)

page.insertText(fitz.Point(ts_h - 30, ts_v - 30), stitle,
               fontsize = 13, color = blue)

# draw the table data
for i, c in enumerate(table):
   beta = c[0] / seats * 180          # express seats as semi circle angles
   color = getColor(c[1])             # avoid multiple color lookups
   # the method delivers point of other end of the constructed arc
   # we will use it as input for next round
   point = page.drawSector(center, point, beta, color = white,
                   fullSector = True, fill = color)
                   
   text = "%s, %i %s" % (c[2], c[0], "Sitze" if c[0] > 1 else "Sitz")
   pos  = fitz.Point(ts_h, ts_v + i*lineheight)
   page.insertText(pos, text, color = blue)
   tl = fitz.Point(pos.x - 30, ts_v - 10 + i*lineheight)
   br = fitz.Point(pos.x - 10, ts_v + i*lineheight)
   rect = fitz.Rect(tl, br)                # legend color bar
   page.drawRect(rect, fill = color), color = color)

# overlay center of circle with white to simulate an auditorium
page.drawCircle(center, radius - 70, color = white, fill = white)
doc.save("piechart2.pdf")



Have a look at https://github.com/rk700/PyMuPDF/edit/master/demo/ to see a full circle version and images of example outputs.



Bul
Alıntı

 
#2

iyiymiş



Bul
Alıntı


Benzer Konular...
Konu: Yazar Cevaplar: Gösterim: Son Mesaj
  Python Program Error in Finding Armstrong Number gulshan212 4 861 23-06-2023, Saat: 10:18
Son Mesaj: gulshan212
  Which Ebook Is Best for Python? swetajoshi 3 1,244 01-03-2023, Saat: 20:56
Son Mesaj: dalaylama
  Best Python Courses palak231 7 1,298 14-02-2023, Saat: 21:29
Son Mesaj: dalaylama
  Python 2 ve 3 arasındaki farklar tuğrul 6 2,718 04-02-2023, Saat: 20:24
Son Mesaj: dalaylama
  python Amsterdam Online Toplantı 21/04/2021 Deli Profesör 2 1,723 10-10-2021, Saat: 14:45
Son Mesaj: Deli Profesör

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Bu konuyu görüntüleyen kullanıcı(lar):
1 Ziyaretçi

   
Türkçe Çeviri: Emre KRMN, Kodlayanlar MyBB, © 2002-2024 MyBB Group.  



Merih Forum® bilgi paylaşım platformu. 2015-∞ Tüm hakları saklıdır.