当前位置:网站首页>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
边栏推荐
- 青训营--数据库实操项目
- Here comes a new chapter in the series of data conversion when exporting with easyexcel!
- all3dp.com网站中全部Arduino项目(2022.7.1)
- Typora installation (no need to enter serial number)
- 指针使用详解
- 线程池概述
- 在线音乐播放器app
- Generate QR code
- Gee data set: export the distribution and installed capacity of hydropower stations in the country to CSV table
- Get the details of the next largest number
猜你喜欢
7.TCP的十一种状态集
Huawei Hongmeng OS, is it OK?
Fabric. JS iText superscript and subscript
【技术随记-08】
With an amount of $50billion, amd completed the acquisition of Xilinx
KMP idea and template code
6.网络-基础
Gee series: unit 7 remote sensing image classification using GEE [random forest classification]
Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]
Gee: create a new feature and set corresponding attributes
随机推荐
Gee series: Unit 4 data import and export in Google Earth engine
ThreadLocal memory leak
RNN recurrent neural network
6.网络-基础
线程池概述
[golang syntax] be careful with the copy of slices
Gee series: unit 9 generate sampling data in GEE [random sampling]
软件测试答疑篇
GRBL 软件:简单解释的基础知识
小程序跳装到公众号
Gee: analyze the change of spatial centroid of remote sensing image [centroid acquisition analysis]
2022-2-14 learning xiangniuke project - Section 7 account setting
"Simple" infinite magic cube
青训营--数据库实操项目
记录sentry的踩坑之路
all3dp. All Arduino projects in com website (2022.7.1)
MySQL foundation --- query (learn MySQL foundation in 1 day)
Online music player app
Gee series: Unit 1 Introduction to Google Earth engine
Determine whether there is an element in the string type