当前位置:网站首页>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 
边栏推荐
- 软件测试 - 概念篇
- Fabric.js 右键菜单
- With an amount of $50billion, amd completed the acquisition of Xilinx
- Fabric. JS background is not affected by viewport transformation
- 2022-2-14 learning xiangniuke project - Section 6 displays login information
- Fabric. JS gradient
- Basic use of form
- [personal test] copy and paste code between VirtualBox virtual machine and local
- Fabric. JS 3 APIs to set canvas width and height
- Gee series: unit 7 remote sensing image classification using GEE [random forest classification]
猜你喜欢

Fabric. JS gradient

Innovation never stops -- the innovation process of nvisual network visualization platform for Excel import

Gee series: Unit 4 data import and export in Google Earth engine

“简单”的无限魔方

Gee series: Unit 1 Introduction to Google Earth engine

Win10 copy files, save files... All need administrator permission, solution

How to write good code - Defensive Programming Guide

Visual Studio导入

“簡單”的無限魔方

在线音乐播放器app
随机推荐
2022-2-14 learning xiangniuke project - section 23, section 5, development login and exit functions
Fabric. JS centered element
Centos8 installation mysql8.0.22 tutorial
Fabric. JS iText sets the color and background color of the specified text
小程序跳装到公众号
Thread pool overview
【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘
Huawei Hongmeng OS, is it OK?
XSS basic content learning (continuous update)
JVM class loading mechanism
Fabric. JS background is not affected by viewport transformation
Operator details
Fabric. JS 3 APIs to set canvas width and height
centos8安裝mysql8.0.22教程
Ubuntu 20.04 installing mysql8
Gee series: unit 7 remote sensing image classification using GEE [random forest classification]
H5 jump applet
操作符详解
Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?
3D 打印机 G 代码命令:完整列表和教程