当前位置:网站首页>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 
边栏推荐
- Thread pool batch processing data
- Appnuim environment configuration and basic knowledge
- “簡單”的無限魔方
- Grbl software: basic knowledge of simple explanation
- 在线音乐播放器app
- 【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘
- Fabric. JS basic brush
- Using QA band and bit mask in Google Earth engine
- Fabric. JS compact JSON
- Zzuli:1061 sequential output of digits
猜你喜欢

Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?

7. Eleven state sets of TCP

操作符详解

Gee series: Unit 1 Introduction to Google Earth engine

KMP idea and template code
![Gee series: unit 7 remote sensing image classification using GEE [random forest classification]](/img/01/ba9441b7b1efaed85c464316740edb.jpg)
Gee series: unit 7 remote sensing image classification using GEE [random forest classification]

【pyinstaller】_ get_ sysconfigdata_ name() missing 1 required positional argument: ‘check_ exists‘

“簡單”的無限魔方

Storage of data

Software testing learning - day 4
随机推荐
Cube magique infini "simple"
idea开发工具常用的插件合集汇总
Minimum value ruler method for the length of continuous subsequences whose sum is not less than s
6.网络-基础
Fabric. JS activation input box
Fabric. JS free draw rectangle
Zzuli:1068 binary number
2022-2-14 learning xiangniuke project - Section 6 displays login information
Brew install * failed, solution
如何写出好代码 — 防御式编程指南
Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
ThreadLocal memory leak
Balsamiq wireframes free installation
软件测试基础篇
JVM class loading mechanism
Opencv LBP features
“简单”的无限魔方
Fabric. JS iText set italics manually
Fabric.js 将本地图像上传到画布背景
brew install * 失败,解决方法