当前位置:网站首页>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 ~
边栏推荐
- 8. Optimizer
- 2021-03-14 - play with generics
- For the first time in China, three Tsinghua Yaoban undergraduates won the stoc best student thesis award
- 2021-03-06 - play with the application of reflection in the framework
- Application of state mode in JSF source code
- 133. Clone map
- 2022 low voltage electrician examination content and low voltage electrician simulation examination question bank
- 14. Draw network model structure
- Capstone/cs5210 chip | cs5210 design scheme | cs5210 design data
- 2. Nonlinear regression
猜你喜欢
Ag9310 design USB type C to hdmi+u2+5v slow charging scheme design | ag9310 expansion dock scheme circuit | type-C dongle design data
Taiwan Xinchuang sss1700 latest Chinese specification | sss1700 latest Chinese specification | sss1700datasheet Chinese explanation
Design method and application of ag9311maq and ag9311mcq in USB type-C docking station or converter
Problems of font legend and time scale display of MATLAB drawing coordinate axis
Definition and classification of energy
Scheme selection and scheme design of multifunctional docking station for type C to VGA HDMI audio and video launched by ange in Taiwan | scheme selection and scheme explanation of usb-c to VGA HDMI c
Ag9310 for type-C docking station scheme circuit design method | ag9310 for type-C audio and video converter scheme circuit design reference
4. Cross entropy
On the concept and application of filtering in radar signal processing
Solve the error: NPM warn config global ` --global`, `--local` are deprecated Use `--location=global` instead.
随机推荐
Basic implementation of pie chart
Smart agricultural technology framework
Recommend a document management tool mendely Reference Manager
Matlab code on error analysis (MAE, MAPE, RMSE)
Authorization code of Axure rp9
2022 chemical automation control instrument examination summary and chemical automation control instrument simulation examination questions
Ag9310 design USB type C to hdmi+u2+5v slow charging scheme design | ag9310 expansion dock scheme circuit | type-C dongle design data
How to use education discounts to open Apple Music members for 5 yuan / month and realize member sharing
String usage in C #
Overall introduction of the project
Complete model training routine
Understanding of prior probability, posterior probability and Bayesian formula
Ag9310 same function alternative | cs5261 replaces ag9310type-c to HDMI single switch screen alternative | low BOM replaces ag9310 design
2022 high voltage electrician examination skills and high voltage electrician reexamination examination
Gnuradio operation error: error thread [thread per block [12]: < block OFDM_ cyclic_ prefixer(8)>]: Buffer too small
5. Over fitting, dropout, regularization
Arm bare metal
4. Strategic Learning
2022 refrigeration and air conditioning equipment operation examination questions and refrigeration and air conditioning equipment operation examination skills
redis的持久化方式-RDB和AOF 两种持久化机制