Matplotlib是Python的绘图库,可以交互使用或嵌入到独立的GUI中。其紧凑的“pyplot”界面类似于MATLAB®的绘图功能。
Year 2013 2014 2015 2016 2017 dfMin 1.091603 0.973346 1.040000 0.855209 1.079500 dfLowerQuartile 1.727191 1.684009 1.275601 1.136703 2.262654 dfUpperQuartile 2.225000 2.000000 1.857570 2.120644 2.435724 dfMax 2.687323 2.350000 2.105000 2.250000 2.566467
考虑单个情节: 导入matplotlib.pyplot作为PLT 导入numpy作为NP #生成样本数据 x = np.linspace(0,10,100) y1 = np.sin(x)#顶部子图的数据 y2 = np.cos(x)#数据fo ...
import matplotlib.pyplot as plt from matplotlib.font_manager import fontManager # This is needed to get color emojis to print matplotlib.use("module://mplcairo.macosx") # This is the font I'm using, available from Google fontManager.addfont("/Users/weinberz/Downloads/Noto_Color_Emoji/NotoColorEmoji-Regular.ttf") plt.figure() plt.text(0.5, 0.6, "🙃", fontname='Noto Color Emoji') plt.text(0.5, 0.5, "🤷🏻♀️", fontname='Noto Color Emoji') plt.show()
import pandas as pd import matplotlib.pyplot as plt def hydrograph_plot(dates, rain, river_flow): # figure and subplots fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 6), sharex=True, gridspec_kw={'height_ratios': [1, 2]}) # bar graph rainfall (inverse y axis) ax1.bar(dates, rain, color='blue', alpha=0.6, label='Chuva (mm)') ax1.set_ylabel('Rainfall (mm)', color='blue') ax1.set_ylim(max(rain), 0) # y axis inverted ax1.set_title('Hydrograph: Rainfall at ' + rain.name + ' and Flow at ' + river_flow.name) # Concatenate colname to the title ax1.legend(loc='upper left') ax1.grid(True, linestyle='--', alpha=0.5) # line graph for river flow ax2.plot(dates, river_flow, color='green', marker='o', label='Nível do Rio (m)') ax2.set_xlabel('Data') ax2.set_ylabel('StreamFlow (m)', color='green') ax2.legend(loc='upper left') ax2.grid(True, linestyle='--', alpha=0.5) # layout and show fig.autofmt_xdate() plt.tight_layout() plt.show() # Example data for multiple locations data = { 'Time': pd.date_range(start='2023-10-01', periods=24, freq='D'), # Time in hours 'Rainfall_Loc1': [0, 2, 5, 10, 8, 4, 2, 0, 0, 1, 3, 6, 9, 7, 5, 3, 1, 0, 0, 0, 0, 0, 0, 0], # Rainfall for Location 1 'Streamflow_Loc1': [10, 12, 15, 50, 80, 70, 60, 50, 40, 35, 30, 25, 20, 18, 16, 14, 12, 11, 10, 10, 10, 10, 10, 10], # Streamflow for Location 1 'Rainfall_Loc2': [0, 1, 3, 7, 12, 10, 6, 3, 1, 0, 0, 0, 2, 4, 6, 8, 7, 5, 3, 1, 0, 0, 0, 0], # Rainfall for Location 2 'Streamflow_Loc2': [15, 18, 20, 60, 90, 85, 75, 65, 55, 50, 45, 40, 35, 30, 25, 20, 18, 16, 15, 15, 15, 15, 15, 15], # Streamflow for Location 2 'Rainfall_Loc3': [0, 0, 0, 0, 1, 2, 4, 6, 8, 10, 12, 10, 8, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0], # Rainfall for Location 3 'Streamflow_Loc3': [20, 22, 25, 70, 100, 95, 85, 75, 65, 60, 55, 50, 45, 40, 35, 30, 25, 22, 20, 20, 20, 20, 20, 20], # Streamflow for Location 3 'Rainfall_Loc4': [0, 5, 8, 0, 1, 3, 14, 6, 5, 20, 1, 10, 0, 16, 2, 21, 10, 0, 0, 0, 0, 0, 0, 0], # Rainfall for Location 3 'Streamflow_Loc4': [20, 22, 25, 70, 100, 95, 85, 75, 65, 60, 55, 50, 45, 40, 35, 30, 25, 22, 20, 20, 20, 20, 20, 20] # Streamflow for Location 3 } df = pd.DataFrame(data)
我需要在线性和对数尺度上绘制一些数据的小提琴图。我很高兴在seaborn中看到log_scale参数。不幸的是,它似乎对我不起作用。我做错了什么吗? ...
i可以使用ax.gridlines()在CATTOPY中绘制网格线,我可以控制是否使用draw_labels = kwarg绘制标签。 但是,我只想绘制标签,而不要画网格线...
ax.gridlines()
如何在matplotlib boxplot时间序列中设置主要X tick?
import matplotlib.pyplot as plt import seaborn as sns import pandas as pd import matplotlib.dates as mdates import random Dates = pd.date_range(start="2020-01-01", end="2020-02-15", freq='D').date data = {'Date': [], 'Values': []} for d in Dates: data['Date'].extend([d] * 10) data['Values'].extend(random.sample(range(1, 101), 10)) df = pd.DataFrame(data) df['Date'] = pd.to_datetime(df['Date']) sns.boxplot(x='Date', y='Values', data=df) plt.xticks(rotation=45) plt.title('Time Series Box Plot') plt.ylabel('Values') plt.xlabel('Date') plt.tight_layout() plt.show()
双星轨道模拟中更新角速度和角度的问题(Python、Matplotlib)
我正在使用 matplotlib 在 python 中创建双星系统的模拟。我希望它根据用户通过我提供的滑块输入进行更改。当我第一次创建这个时没有任何真实的
I有一些放射线量,可以在嵌入式图中选择细分线的颜色和宽度。当我选择新的颜色或宽度时,我无法清除图,而新的图位于Origi下方...
有人可以帮我创建具有以下结构的绘图布局: 一张CD 甲/乙EF 生长激素 其中 A、B 是 3D 图(fig.add_subplot(241,projection='3d')),C、D、E、F、G、H 是常规 2D 图...
我有 3 维分散数据 x、y、z。 我想将 x 和 y 的箱中 z 的平均值绘制为十六进制图或二维直方图。 有没有 matplotlib 函数可以做到这一点? 我只能上来了...
我有一个简单的 Jupyter 笔记本,其中包含使用 ipympl 渲染为 ipywidget 的 matplotlib 图。我想让每个图都拉伸到视口的宽度。 ipympl 文档说
为什么子图不能嵌套在 gridspec 中以在 matplotlib 中保持其字幕分开?
我希望这段代码: 将 matplotlib.pyplot 导入为 plt 图 = plt.figure(figsize=(8, 6)) 图_gridspec = 图.add_gridspec(1, 1) top_subfig = Fig.add_subfigure(fig_gridspec[(0, 0)]) 顶部_子图。
为什么子图不能嵌套在 gridspec 中以在 matplotlib 中保持其字幕分开?
我希望这段代码: 将 matplotlib.pyplot 导入为 plt 图 = plt.figure(figsize=(8, 6)) 图_gridspec = 图.add_gridspec(1, 1) top_subfig = Fig.add_subfigure(fig_gridspec[(0, 0)]) 顶部_子图。
我正在尝试绘制这个 xarray 数据数组(文件在这里): 文件循环: 数组([[66.66666667, 61.53846154, 52.94117647, ..., 66.66666667, ...
使用 Visual Studio 的 Python 工具在 Visual Studio 中使用 Matplotlib 进行绘图
我刚开始在 Python 代码中使用 PTVS。我之前使用过 Spyder,因为它是与 Anaconda 发行版一起提供的。这是我遇到的问题。 我正在尝试创建两个图,并在