当前位置:网站首页>How does Matplotlib generate multiple pictures in turn & only save these pictures without displaying them in the compiler
How does Matplotlib generate multiple pictures in turn & only save these pictures without displaying them in the compiler
2022-07-08 01:26:00 【Bosong】
Catalog
1. Introduction to import library
2. Image generation code introduction
1. Introduction to import library
import os
import inspect
import pandas as pd
import numpy as np
from datetime import datetime
# stay jupyter notebook Display image in
import matplotlib.pyplot as plt
%matplotlib inline
# Show Chinese in the picture 、 Minus sign, etc
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
import matplotlib
# stay Python The generated image is not displayed in
matplotlib.use('Agg')Before the first part 5 Libraries involve data processing , The second part jupyter notebook Specific settings , The third part is about Chinese drawing names 、 Display of legend and minus sign , The fourth part focuses on the generated multiple pictures 、 Not displayed in the compiler .
2. Image generation code introduction
# Variable initialization settings
emer_sort = pd.DataFrame(columns = ['STARTTIME','WEEK','TIME','MINUTE','BELONGEDLINE','STATIONNAMES'])
# Classify according to a column of data
emer_stagroup = emer.groupby('STATIONNAMES')
# Count effective data days k, Prepare for drawing multiple subgraphs
k = 0
for sta_name, sta_group in emer_stagroup:
# according to STARTTIME Column sorting
emer1 = sta_group.sort_values(by = 'STARTTIME')
emer_timegroup = emer1.groupby('TIME')
for time_name, time_group in emer_timegroup:
# Select a date with sufficient sample size TIME - 5min Spaced samples ,192 yes 16 Hours
if time_group.shape[0] < 192:
continue
else:
# Add all sample points for a day
emer_sort = emer_sort.append(time_group)
k = k + 1
# longitudinal 、 Horizontal axis data
time_group_flow = time_group['FLOW']
time_group_minute = time_group['MINUTE'].to_list()
fig, ax = plt.subplots(figsize = (10, 7))
# Axis scale font settings
plt.tick_params(labelsize=13)
ax.plot(time_group_flow.values)
# Axis title settings
ax.set_xlabel('Date-time', fontsize=14)
ax.set_ylabel('Flow', fontsize=14)
# Title Setting
ax.set_title(time_group['STATIONNAMES'].values[0], fontsize=14)
# Abscissa scale setting - How to display the date
dates = pd.to_datetime(time_group['MINUTE'])
dates = dates.apply(lambda d: d.strftime('%H:%M'))
ax.set_xticks(np.arange(len(dates))[12::24])
# Abscissa scale from 12 The number begins 、 every other 24 The number shows , tilt 45°
_ = ax.set_xticklabels(dates[12::24], rotation=45)
# Storage
plt.savefig('./fig/fig_lots/flow_%s.png'%k, dpi=200)
# Reset dataframe The line of label , and drop The previous label
emer_sort_set = emer_sort.reset_index(drop = True)If the program reports an error “Out of bounds Datetime: Out of bounds nanosecond timestamp: ...”, And point to this line of code dates = pd.to_datetime(time_group['MINUTE']), The current solution is to Comment out this line and the following line .( The question is Another article Some discussion , But there is no conclusion >_<)
Welcome to exchange and discuss ~
边栏推荐
- Markdown learning (entry level)
- 5. Over fitting, dropout, regularization
- C# ?,?.,?? .....
- Use "recombined netlist" to automatically activate eco "APR netlist"
- npm 内部拆分模块
- Gnuradio operation error: error thread [thread per block [12]: < block OFDM_ cyclic_ prefixer(8)>]: Buffer too small
- How to use education discounts to open Apple Music members for 5 yuan / month and realize member sharing
- Two methods for full screen adaptation of background pictures, background size: cover; Or (background size: 100% 100%;)
- Chapter improvement of clock -- multi-purpose signal modulation generation system based on ambient optical signal detection and custom signal rules
- Redis 主从复制
猜你喜欢

解决报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

130. Surrounding area

2021 Shanghai safety officer C certificate examination registration and analysis of Shanghai safety officer C certificate search

Common effects of line chart

Redis master-slave replication

Basic realization of line chart (II)

USB type-C docking design | design USB type-C docking scheme | USB type-C docking circuit reference

Running OFDM in gnuradio_ RX error: gr:: Log: info: packet_ headerparser_ b0 - Detected an invalid packet at item ××

Complete model verification (test, demo) routine

How to write mark down on vscode
随机推荐
Multi purpose signal modulation generation system based on environmental optical signal detection and user-defined signal rules
Saving and reading of network model
Gnuradio3.9.4 create OOT module instances
5. Discrete control and continuous control
Measure the voltage with analog input (taking Arduino as an example, the range is about 1KV)
Running OFDM in gnuradio_ RX error: gr:: Log: info: packet_ headerparser_ b0 - Detected an invalid packet at item ××
The Ministry of housing and urban rural development officially issued the technical standard for urban information model (CIM) basic platform, which will be implemented from June 1
Smart agricultural technology framework
2022 tea master (intermediate) examination questions and tea master (intermediate) examination skills
On the concept and application of filtering in radar signal processing
The difference between distribution function and probability density function of random variables
Call (import) in Jupiter notebook ipynb . Py file
How to use education discounts to open Apple Music members for 5 yuan / month and realize member sharing
Use "recombined netlist" to automatically activate eco "APR netlist"
Parade ps8625 | replace ps8625 | EDP to LVDS screen adapter or screen drive board
4. Apprentissage stratégique
Micro rabbit gets a field of API interface JSON
Cs5261type-c to HDMI alternative ag9310 | ag9310 alternative
2022 R1 fast opening pressure vessel operation test question bank and R1 fast opening pressure vessel operation free test questions
2022 examination for safety production management personnel of hazardous chemical production units and new version of examination questions for safety production management personnel of hazardous chem