python如何绘制降水图
python能快速解决日常工作中的小任务,比如数据展示。python做数据展示,主要用到matplotlib库,使用简单的代码,就可以很方便的绘制折线图、柱状图等。使用Java等,可能还需要配合html来进行展示,十分繁琐。
各种平面图的绘制代码:
''' File Name: draw Description: 图形绘制。十分有用,对于工作中实验性的项目,可以快速展示效果。如果使用java,还需要配合前端展示。 ''' import matplotlib.pyplot as plt import numpy as np # 模块取别名 # 直方图 def draw_hist(): mu = 100 sigma = 20 x = mu + sigma * np.random.randn(20000) # 样本数量 plt.hist(x, bins=100, color='green', normed=True) # bins:显示有几个直方,normed是否对数据进行标准化 plt._show() # 条形图 def draw_bar(): y = [20, 10, 30, 25, 15] # Y轴数据 index = np.arange(5) # X轴数据,也可以是index = [0,5] plt.bar(left=index, height=y, color='blue', width=0.5) plt.show() # 折线图 def draw_plot(): x = np.linspace(-10, 10, 100) # -10到10,100个点 y = x ** 3 # x的3次幂 plt.plot(x, y, linestyle='--', color='orange', marker='<') plt.xlabel('X') plt.ylabel('Y') plt.show() # 散点图 def draw_scatter(): x = np.random.randn(1000) y = x + np.random.randn(1000) * 0.5 plt.scatter(x, y, s=5, marker='<') # s表示面积,marker表示图形 plt.show() # 饼状图 def draw_pie(): labels = 'A', 'B', 'C', 'D' # 4个模块 fracs = [15, 30, 45, 10] # 每个模块占比例 plt.axes(aspect=1) # 使x、y轴比例相同 explode = [0, 0.5, 0, 0] # 突出某一部分区域 plt.pie(x=fracs, labels=labels, autopct='%.0f%%', explode=explode) # autopct显示百分比 plt.show() # 带图例 def draw_with_legend(): x = np.arange(1, 11, 1) # x轴坐标,1开始,11结束,步长为1 plt.plot(x, x * 2) # 第一条线,x,y坐标 plt.plot(x, x * 3) plt.plot(x, x * 4) plt.legend(['Normal', 'Fast', 'Faster']) # 设置图例,与上面的线对应 plt.grid(True, color='green', linestyle='--', linewidth=1) # 绘制网格 plt.show() # start if __name__ == '__main__': # draw_hist() # draw_bar() draw_plot() # draw_scatter() # draw_pie() # draw_with_legend()
3D图的绘制代码:
''' File Name: draw_3d Description: 3D绘图 ''' import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # 3D 绘制 def draw_3D(): fig = plt.figure() # 定义一个窗口 ax = Axes3D(fig) # 绘制3D坐标 # 设置x、y、z的值 x = np.arange(-4, 4, 0.25) y = np.arange(-4, 4, 0.25) x, y = np.meshgrid(x, y) # x-y 平面的网格 r = np.sqrt(x ** 2 + y ** 2) z = np.sin(r) # z值 # 做出一个三维曲面,并将一个 colormap rainbow 填充颜色,之后将三维图像投影到 XY 平面上做一个等高线图 # rstride 和 cstride 分别代表 row 和 column 的跨度。 ax.plot_surface(x, y, z, rstride=1, cstride=1, cmap=plt.get_cmap('rainbow')) # 添加 XY 平面的等高线 ax.contourf(x, y, z, zdir='z', offset=-2, cmap=plt.get_cmap('rainbow')) ax.set_zlim(-2, 2) plt.show() # 展示 # start if __name__ == '__main__': draw_3D()
以上是python如何绘制降水图的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undress AI Tool
免费脱衣服图片

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

创建Python虚拟环境可使用venv模块,步骤为:1.进入项目目录执行python-mvenvenv创建环境;2.Mac/Linux用sourceenv/bin/activate、Windows用env\Scripts\activate激活;3.使用pipinstall安装包、pipfreeze>requirements.txt导出依赖;4.注意避免将虚拟环境提交到Git,并确认安装时处于正确环境。虚拟环境能隔离项目依赖防止冲突,尤其适合多项目开发,编辑器如PyCharm或VSCode也

使用multiprocessing.Queue可在多个进程间安全传递数据,适合多生产者和消费者的场景;2.使用multiprocessing.Pipe可实现两个进程间的双向高速通信,但仅限两点连接;3.使用Value和Array可在共享内存中存储简单数据类型,需配合Lock避免竞争条件;4.使用Manager可共享复杂数据结构如列表和字典,灵活性高但性能较低,适用于复杂共享状态的场景;应根据数据大小、性能需求和复杂度选择合适方法,Queue和Manager最适合初学者使用。

使用boto3上传文件到S3需先安装boto3并配置AWS凭证;2.通过boto3.client('s3')创建客户端并调用upload_file()方法上传本地文件;3.可指定s3_key作为目标路径,若未指定则使用本地文件名;4.应处理FileNotFoundError、NoCredentialsError和ClientError等异常;5.可通过ExtraArgs参数设置ACL、ContentType、StorageClass和Metadata;6.对于内存数据,可使用BytesIO创建字

PythonlistScani ImplementationAking append () Penouspop () Popopoperations.1.UseAppend () Two -Belief StotetopoftHestack.2.UseP OP () ToremoveAndreturnthetop element, EnsuringTocheckiftHestackisnotemptoavoidindexError.3.Pekattehatopelementwithstack [-1] on

使用Pythonschedule库可轻松实现定时任务,首先通过pipinstallschedule安装库,接着导入schedule和time模块,定义需要定时执行的函数,然后使用schedule.every()设置时间间隔并绑定任务函数,最后通过while循环中调用schedule.run_pending()和time.sleep(1)持续运行任务;例如每10秒执行一次任务可写为schedule.every(10).seconds.do(job),支持按分钟、小时、天、周等周期调度,也可指定具体

EnsurePythonisinstalledandaddedtoPATHbycheckingversioninterminal;2.Savefilewith.pyextension;3.UseCtrl Btorunviadefaultbuildsystem;4.CreateacustombuildsystemifneededbygoingtoTools>BuildSystem>NewBuildSystem,enteringthecorrectcmdforyourPythonvers

Usetracemalloctotrackmemoryallocationsandidentifyhigh-memorylines;2.Monitorobjectcountswithgcandobjgraphtodetectgrowingobjecttypes;3.Inspectreferencecyclesandlong-livedreferencesusingobjgraph.show_backrefsandcheckforuncollectedcycles;4.Usememory_prof

生存分析用于研究事件发生的时间,Python中常用lifelines和scikit-survival实现。1.安装lifelines库并准备包含时间与事件状态的数据;2.使用Kaplan-Meier估计器绘制生存曲线以可视化事件未发生的概率;3.通过Cox比例风险模型分析变量对事件时间的影响,并检查模型假设;4.注意删失数据的处理,确保event列正确标记删失与事件发生。
