����λ�ã���ҳ > �����̳� > �̳� > ʹ��Python��matplotlib�����ͼ��
���Ľ��������ʹ�� Python �� matplotlib �â»Í¼ï¿½ï¿½ï¿½ï¿½Â¼Ò»Ð©ï¿½ï¿½ï¿½ÃµÄ»ï¿½Í¼ demo ����
���Ľ��������ʹ��Python��matplotlib�����ͼ��������¼һЩ���õĻ�ͼʾ�����롣
��װmatplotlib�⣺
# �������л������⻷����
pip install matplotlib
������ʾ���ã�
�°��matplotlib�Ѿ�֧��������˹��ܣ���˿���ֱ����������ΪTimes New Roman��SimSun�����壩����ʵ��Ӣ����Times New Roman��ʾ��������������ʾ��
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = ['Times New Roman','SimSun']
����ͼ�͵���ͼ��
ʹ��plot�������Ի�������ͼ�͵���ͼ��ͨ��marker�������õ����ʽ��markersize�������õ�Ĵ�С��
import matplotlib.pyplot as plt
# ������������ΪTimes New Roman������
plt.rcParams['font.family'] = ['Times New Roman','SimSun']
# ��������
x = range(0, 6)
y = [i**3 for i in x]
# ���Ƶ���ͼ
plt.plot(x, y, marker='o', markersize=6, label='y=x^3')
# �����������ǩ
plt.xlabel('x')
plt.ylabel('y')
# ���������᷶Χ
plt.xlim(0)
plt.ylim(0)
# ����ͼ��
plt.legend()
# ���ý��ղ���
plt.tight_layout(pad=0.1)
# ����ͼƬ
plt.savefig('plot.png')
��״ͼ�Ͷѻ���״ͼ��
ʹ��bar����������״ͼ��ͨ��bottom�������Ի��ƶѻ���״ͼ��
# ��������
x = range(1, 6)
y1 = [1 for i in x]
y2 = [i for i in x]
# ���ƶѻ���״ͼ
plt.bar(x, y1, color='tab:blue', edgecolor='black', label='y1=1', width=0.5)
plt.bar(x, y2, bottom=y1, color='tab:orange', edgecolor='black', label='y2=x', width=0.5)
������ϵ㣺
��ʱ��Ҫ����״ͼ������y��Ķϵ㣬����ͨ����������ͬ��ͼ�������ò�ͬ��y�᷶Χ��Ȼ��������ͼ֮�����ӽض��ߵķ�ʽ��ʵ�֡�
# ��������
x = range(1, 5)
y = [i**3 for i in x]
# �ֱ������������ͼ
b1 = ax1.bar(x, y, color='tab:blue', edgecolor='black', label='y1=1', width=0.5)
b2 = ax2.bar(x, y, color='tab:blue', edgecolor='black', label='y1=1', width=0.5)
# ��ʾ����
ax1.bar_label(b1, fmt='%d', label_type='edge')
ax2.bar_label(b2, fmt='%d', label_type='edge')
# ������ͼ�������᷶Χ
ax1.set_ylim(15)
ax1.set_yticks([20, 40, 60])
# ɾ����ͼ���±߿�
ax1.spines['bottom'].set_visible(False)
# ������ͼ��x��
ax1.xaxis.set_visible(False)
# ������ͼ�������᷶Χ
ax2.set_ylim(0, 9)
ax2.set_yticks([0, 2, 4, 6, 8])
# ɾ����ͼ���ϱ߿�
ax2.spines['top'].set_visible(False)
# ���ӽض��ߣ�����ͼ�߶ȱ���Ϊ1:2�����Խض��ߵ�y����Ҳ��Ҫ����������
d = .015
kwargs = dict(transform=ax1.transAxes, color='k', clip_on=False)
ax1.plot((-d, +d), (-2*d, +2*d), **kwargs)
ax1.plot((1 - d, 1 + d), (-2*d, +2*d), **kwargs)
kwargs.update(transform=ax2.transAxes)
ax2.plot((-d, +d), (1 - d, 1 + d), **kwargs)
ax2.plot((1 - d, 1 + d), (1 - d, 1 + d), **kwargs)
�ο����ϣ�
С���Ƽ��Ķ��������ߣ� ywang_wnlo
�������ӣ� https://ywang-wnlo.github.io/posts/731b80f7/
��Ȩ������ �������������³��ر������⣬������BY-NC-SA����Ð�顣ת����ע��
ʹ��Blender���ɳ���ģ��
�Ķ�ȫ����������ERA5�����ط���
�Ķ�Xpath���������﷨
�Ķ�����ѧϰ�������繹�����£�
�Ķ���ΪMateƷ��ʢ�䣺HarmonyOS NEXT�ӳ�����Ϸ���ܵõ�����ͷ�
�Ķ�ʵ�ֶ��󼯺���DataTable���໥ת��
�Ķ�Ӳ�̵Ļ���֪ʶ��ѡ��ָ��
�Ķ�������й��ƶ��ı�ͼ��ײ�
�Ķ�����NEXTԪ�����������ѿ����ϼ���Ʒ
�Ķ��ᳲ���С������������Ƽ��رշ���
�Ķ������ArcMap�����н���դ��ͼ���ز�������
�Ķ��㷨�����ݽṹ 1 - ģ��
�Ķ���Ѷ�����߿ͷ���Ӫ��ϵͳ����
�Ķ���Ѷ��Ƶҹ��ģʽ���ý̳�
�Ķ����ں���NEXT��Ѫ���Ŵ���������������
�Ķ�5. Spring Cloud OpenFeign ����ʽ WebService �ͻ��˵ij���ϸʹ��
�Ķ�Java����ģʽ����̬�����Ͷ�̬�����ĶԱȷ���
�Ķ�Win11�ʼDZ����Զ�����Ӧ�õ���ɫ����ʾ����
�Ķ�˼�� V1.5.6 ��׿��
��ս�귨 V7.5.0 ��׿��
У��������������׵������� V1.0 ��׿��
��˸֮�� V1.9.7 ��׿��
������Ե����� v1.0.4 ��׿��
������֮ŠV5.2.3 ��׿��
��������������Դ V1.0 ��׿��
���֮Ϣ V1.0 ��׿��
��ħ������������䣩 V1.0 ��׿��
���ں�������ϵ�����������������վ�����������������Ƽ�����
Ƶ�� ����Ƶ��������ר������������׿�������app����
�Ƽ� ��Ô���������°��������ܿ������ز���
���� ����ɫ������������ ���������ս������������
ɨ��ά�����������ֻ��汾��
ɨ��ά����������΢�Ź��ںţ�
��վ�������������������ϴ��������ַ���İ�Ȩ���뷢�ʼ�[email protected]
��ICP��2022002427��-10 �湫��������43070202000427��© 2013~2025 haote.com ������