Myluzh Blog

Strive to become a dream architect.

Python matplotlib 绘制折线图(多坐标系)

2023-7-13 myluzh Python

0x01 图像 0x02 代码 import matplotlib.pyplot as plt import random # 支持中文 from pylab import mpl mpl.rcParams['font.sans-serif'] = ['Arial Unicode MS'] mpl.rcParams['axes.unicode_minus'] = False # 用来解决不能使用汉字问题,需要导入matplotlib # 准备x y 数据 x = range(1, 31) y_hangzhou = [random.uniform(35, 42) for i in x] y_beijing = [random.uniform(34, 39) for i in x] # nrows/ncols设置成有几行几列的坐标系。返回fig:图对象,axes:返回相应数量的坐标系 fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(20, 8), dpi=50) axes[0].plot(x, y_hangzhou, color="b", ...

阅读全文>>

标签: python matplotlib

评论(0) (174)

Python matplotlib 绘制折线图(单坐标系)

2023-7-13 myluzh Python

0x01 图像 0x02 代码 import matplotlib.pyplot as plt import random # 支持中文 from pylab import mpl mpl.rcParams['font.sans-serif'] = ['Arial Unicode MS'] mpl.rcParams['axes.unicode_minus'] = False # 用来解决不能使用汉字问题,需要导入matplotlib # 准备x y 数据 x = range(1, 31) y_hangzhou = [random.uniform(35, 42) for i in x] y_beijing = [random.uniform(34, 39) for i in x] # 创建画布 plt.figure(figsize=(10, 5), dpi=70) # 绘制图像 plt.plot(x, y_hangzhou, color="b", linestyle='-', label='上海') plt.plot(x, y_beijing, color="r", linestyle...

阅读全文>>

标签: python matplotlib

评论(0) (119)

Python selenium WebDriver 参数

2023-7-6 myluzh Python

设置 WebDriver 的选项参数可以使用 Options 类,具体如下所示: from selenium import webdriver from selenium.webdriver.chrome.options import Options # 创建 ChromeOptions 实例 options = Options() # 设置选项参数 options.add_argument("--headless") # 无界面模式运行 options.add_argument("--disable-gpu") # 禁用GPU加速 options.add_argument("--window-size=1920,1080") # 设置窗口大小 # 创建 Chrome 浏览器实例,并传入选项参数 driver = webdriver.Chrome(options=options) 其中,add_argument() 方法用于添加选项参数。你可以根据需要选择适合的选项参数来配置你的 WebDriver 实例。常见的选项参数包括: --headless:启用无界面...

阅读全文>>

标签: python selenium WebDriver

评论(0) (140)

Python selenium在Chrome中设置传感器(位置)

2023-5-25 myluzh Python

是否可以使用 Chrome Headless 设置自定义位置坐标?我在里面找不到。 Is it possible to set custom location coordinates with Chrome Headless? I can't find it in the Devtools protocol API. Is there a workaround available? 解决方案 I googled it and got many methods. I try one by one, almost all of them turn out outdated. Then I find out a solution, use chrome devtools protocol to achieve that. The small example code below, that it uses the most common tool selenium to execute chrome devtools protocol command. import time from selenium.webdr...

阅读全文>>

标签: selenium Chrome 传感器 位置 虚拟定位

评论(0) (204)

Django-Form与ModelForm

2023-5-24 myluzh Python

0x01 原始的Form表单 用户提交数据没有校验。 页面上没有错误提示。 页面上每个字段都要写一遍。 关联的数据还需要手动获取后循环展示在页面中。 0x02 Django组件-Form views.py from django.forms import Form class MyForm(Form): user = forms.CharField(widget=forms.Input) pwd = form.CharFiled(widget=forms.Input) email = form.CharFiled(widget=forms.Input) def user_add(request): if request.method == "GET": form = MyForm() return render(request, 'user_add.html', {"form": form}) user_add.html <form method="post"> <!--以前的写法写in...

阅读全文>>

标签: django

评论(0) (180)

python调用OPENAI_ChatGPT类

2023-5-24 myluzh Python

0x01 前言 python有直接现成的OPENAI模块,为了锻炼下自己,写了个基础的调用类。 0x02 代码 需要更改成你自己的open_ai_key,还有就是要设置下http代理,因为目前GPT只能国外访问。 class OPENAI: def __init__(self): self.open_ai_key = "sk-DR5GkhpENIwerq9qfmYqT3BlbkFJXeWBFt4melgpmv8PFr" self.open_ai_api = "https://api.openai.com/v1/chat/completions" self.model = "gpt-3.5-turbo-0301" def openai_reply_requests(self, message): error_counter = 0 while error_counter <= 3: headers = { "Content-Type": "a...

阅读全文>>

评论(0) (140)