微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

matplotlib python 列表全面吗?

如何解决matplotlib python 列表全面吗?

我想做一个简单的图表来显示每天所有约会的总利润。结果显示类似的东西

enter image description here

这绝对是不对的。 我知道这个问题在我的 views.py 列表中很全面,但不知道如何解决它.. 任何帮助表示赞赏

models.py

class Service(models.Model):
  service_name = models.CharField(max_length=50)
  service_price = models.DecimalField(max_digits=8,decimal_places=2)
  physician = models.ForeignKey('Physician',on_delete=models.CASCADE)

  def __str__(self):
        return self.service_name

class Appointment(models.Model):
  appointment_date = models.DateField(null=True)
  appointment_time = models.TimeField(null=True)
  patient = models.ForeignKey('Patient',on_delete=models.CASCADE)
  reseptionist = models.ForeignKey('Reseptionist',on_delete=models.SET_NULL,blank=True,null=True)
  service = models.ForeignKey('Service',on_delete=models.CASCADE)
  physician = models.ForeignKey('Physician',on_delete=models.CASCADE)

plots.py

import matplotlib as mpl
mpl.use('Agg')

import matplotlib.pyplot as plt
import base64
from io import BytesIO

def get_graph():
  buffer = BytesIO()
  plt.savefig(buffer,format="png")
  buffer.seek(0)
  img = buffer.getvalue()
  g = base64.b64encode(img)
  g = g.decode("utf-8")
  buffer.close()
  return g


def line_plot(x,y):
  plt.figure(figsize=(4,4)) 
  plt.plot(x,y)
  return get_graph()

views.py

from .plots import line_plot
def index(request): 
    prices = Appointment.objects.all()
    revenue = [x.service.service_price for x in prices]
    
    day = [x.appointment_date for x in prices ]
    
    c = pie_plot(revenue,day)
    
    context = {'chart': c }

    return render(request,'index.html',context)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?