当前位置:网站首页>Matplotlib double Y axis + adjust legend position
Matplotlib double Y axis + adjust legend position
2022-07-02 05:39:00 【Bluestone horizontal knife riding horse】
from matplotlib.pyplot import rcParams
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib
# Import data 、 Processing data ( This step can be ignored by readers )
dataframe = pd.read_csv('D:/ Epidemic forecast /USA.csv',usecols=[1])#658 strip
dataset_old = dataframe.values
diff1=[]
diff1=dataset_old .diff()
# Prevent Chinese miscoding
rcParams['font.sans-serif'] = 'kaiti'
# Generate a time series
time =pd.to_datetime(np.arange(0,658), unit='D',
origin=pd.Timestamp('2020-1-21'))
# Create a canvas
fig=plt.figure(figsize=(18,6))#figsize For canvas size
# Add a sub view on the canvas
ax1=fig.add_subplot(111)
ax1.plot(time,dataset_old,color='#1bb9f6',linestyle='--')
ax1.set_title(' The cumulative number of infections in the United States and the number of new infections per day ',fontsize=20)
ax1.set_xlabel(' date / God ',fontsize=20)# Set up x Axis
ax1.set_ylabel(' Cumulative number of infections / Ten million ',fontsize=20)# Set the left side y Axis
ax2=ax1.twinx()# Very important
ax2.plot(time,diff1,color='#9d5dfc',linestyle='-')
ax2.set_ylabel(' New infections per day / people ',fontsize=20)# Set the... On the right y Axis
fig.legend([" Cumulative number of confirmed cases ",' New infections per day '],fontsize=20,loc='upper left',bbox_to_anchor=(0.13,0.9))
#loc Is the legend position ,bbox_to_anchor(n1,n2),n1 Move left and right ,n2 Move up and down , Manually adjust the legend position
give the result as follows 
边栏推荐
- 6.网络-基础
- How matlab marks' a 'in the figure and how matlab marks points and solid points in the figure
- Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
- all3dp. All Arduino projects in com website (2022.7.1)
- Basic use of form
- 软件测试答疑篇
- Importation de studio visuel
- Installation du tutoriel MySQL 8.0.22 par centos8
- Youth training camp -- database operation project
- KMP idea and template code
猜你喜欢

RNN recurrent neural network

Gee series: Unit 2 explore datasets

centos8安装mysql8.0.22教程

Mysql基础---查询(1天学会mysql基础)

centos8安裝mysql8.0.22教程
![Gee series: unit 8 time series analysis in Google Earth engine [time series]](/img/a6/648ff959af93c22dc8605215a90535.jpg)
Gee series: unit 8 time series analysis in Google Earth engine [time series]

在线音乐播放器app

"Simple" infinite magic cube

Youth training camp -- database operation project

5g market trend in 2020
随机推荐
软件测试基础篇
生成二维码
Gee series: unit 8 time series analysis in Google Earth engine [time series]
H5 jump applet
all3dp.com网站中全部Arduino项目(2022.7.1)
Minimum value ruler method for the length of continuous subsequences whose sum is not less than s
Gee: create a new feature and set corresponding attributes
Generate QR code
Storage of data
金融门户相关信息
7. Eleven state sets of TCP
KMP idea and template code
"Original, excellent and vulgar" in operation and maintenance work
3D printer G code command: complete list and tutorial
Fabric. JS right click menu
在线音乐播放器app
How matlab marks' a 'in the figure and how matlab marks points and solid points in the figure
7.TCP的十一种状态集
XSS basic content learning (continuous update)
来啦~ 使用 EasyExcel 导出时进行数据转换系列新篇章!