时间:2021-05-22
主要问题
1.介绍
如题,画双轴子图不能显示 x-轴坐标轴标签,似乎 “双轴”与“子图”存在冲突有关,当前版本是 anaconda 3.7.4。比较奇葩的是 我家里的电脑,3.7.3 却没这个问题。但我把公司电脑换成 3.7.3 问题依旧,崩溃。
import pandas as pdimport matplotlib.pyplot as plta = pd.date_range('2020-07-01','2020-07-20')b = [2,3,4,5,7,9,20,20,11,13,1,2,3,9,23,2,6,7,7,7]c = [0.20,0.1,0.13,0.1,0.2,0.3,0.9,0.23,0.2,0.6,0.7,0.7,0.7,0.2,0.3,0.4,0.5,0.7,0.9,0.2]data = pd.DataFrame({'a':a,'b':b,'c':c})data = data.groupby(['a'])['b','c'].sum()nrow = 2ncol = 1fig = plt.figure(figsize=(ncol*10,nrow*4))ax_1 = plt.subplot2grid((nrow, ncol), (0, 0), colspan=1, rowspan=1,facecolor = 'black')ax_2 = plt.subplot2grid((nrow, ncol), (1, 0), colspan=1, rowspan=1,facecolor = 'black')data['b'].plot(ax = ax_1,color = 'r')data['c'].plot(ax = ax_1.twinx(),color = 'y')2.只画双轴,正常显示
import pandas as pdimport matplotlib.pyplot as plta = pd.date_range('2020-07-01','2020-07-20')b = [2,3,4,5,7,9,20,20,11,13,1,2,3,9,23,2,6,7,7,7]c = [0.20,0.1,0.13,0.1,0.2,0.3,0.9,0.23,0.2,0.6,0.7,0.7,0.7,0.2,0.3,0.4,0.5,0.7,0.9,0.2]data = pd.DataFrame({'a':a,'b':b,'c':c})data = data.groupby(['a'])['b','c'].sum()nrow = 1ncol = 1fig = plt.figure(figsize=(ncol*10,nrow*4))ax_1 = plt.subplot2grid((nrow, ncol), (0, 0), colspan=1, rowspan=1,facecolor = 'black')# ax_2 = plt.subplot2grid((nrow, ncol), (1, 0), colspan=1, rowspan=1,facecolor = 'black')data['b'].plot(ax = ax_1,color = 'r')data['c'].plot(ax = ax_1.twinx(),color = 'y')3.只画子图,也能正常显示
import pandas as pdimport matplotlib.pyplot as plta = pd.date_range('2020-07-01','2020-07-20')b = [2,3,4,5,7,9,20,20,11,13,1,2,3,9,23,2,6,7,7,7]c = [0.20,0.1,0.13,0.1,0.2,0.3,0.9,0.23,0.2,0.6,0.7,0.7,0.7,0.2,0.3,0.4,0.5,0.7,0.9,0.2]data = pd.DataFrame({'a':a,'b':b,'c':c})data = data.groupby(['a'])['b','c'].sum()nrow = 2ncol = 1fig = plt.figure(figsize=(ncol*10,nrow*4))ax_1 = plt.subplot2grid((nrow, ncol), (0, 0), colspan=1, rowspan=1,facecolor = 'black')ax_2 = plt.subplot2grid((nrow, ncol), (1, 0), colspan=1, rowspan=1,facecolor = 'black')data['b'].plot(ax = ax_1,color = 'r')data['c'].plot(ax = ax_2,color = 'y')到此这篇关于matplotlib 画双轴子图无法显示x轴的解决方法的文章就介绍到这了,更多相关matplotlib 双轴子无法显示x轴内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了Python使用matplotlib绘图无法显示中文问题的解决方法。分享给大家供大家参考,具体如下:在python中,默认情况下是无法显示中文的,
很多时候可能需要在一个图中画出多条函数图像,但是可能y轴的物理含义不一样,或是数值范围相差较大,此时就需要双y轴。matplotlib和seaborn都可以画双
在使用matplotlib模块时画坐标图时,往往需要对坐标轴设置很多参数,这些参数包括横纵坐标轴范围、坐标轴刻度大小、坐标轴名称等在matplotlib中包含了
前言所有的图表除了饼图都有X轴和Y轴,默认情况下,x轴显示在图表的底部,y轴显示在左侧(多个y轴时可以是显示在左右两侧),通过设置chart.inverted=
先声明一下所用的数据集第一个图如下这个图主要在于x轴的顺序设置上,如果按不做任何处理的话>3那个就会在2之前,解决方法是b[,1]