日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python怎么绘制渐变图_用Python画colorbar渐变图+修改刻度大小+修改渐变颜色

發布時間:2024/7/23 python 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python怎么绘制渐变图_用Python画colorbar渐变图+修改刻度大小+修改渐变颜色 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Draw Gradient Color Map using python

github源碼地址:

歡迎關注我!

pratical_skills_tools

Draw Gradient Color Map

Dependencies

pandas

matplotlib

numpy

seaborn

You can configure it using pip install XXX in terminal.

Results

figure1:

figure2:

Using and Explanation

1.改變顏色的種類

在程序path_Results.py文件中,修改plot_results_path函數中的:

lc = gd.colorline(x, y, z, cmap=plt.get_cmap('cool'), linewidth=linewidth_car) # 'jet' #'cool'

中的cmap=plt.get_cmap('cool')參數即可。可以設置的有:

參考 matplotlib tutorials中的colors部分

舉例:

2.改變圖例的標注范圍

可以進行圖例colorbar刻度的調整,包括平移和比例放縮:

在程序path_Results.py文件中,plot_gd_bar函數中的:

def plot_gd_bar(fig, ax, lc, max_pro, max_tran=0, cars_num=1, car_num=0, offset=0):

參數:

max_pro: 調整比例

max_tran: 調整偏移量

比如main.py中函數調用的時候:

cb = paths.plot_gd_bar(fig, ax, lc, result0[-1, 2], 10)

#最后兩個參數一個是調整比例,一個是調整偏移量

比例放縮的含義:原本[0,5]可以調整為[0,10],在上面函數調用中的result0[-1, 2]處寫上2即可;

平移的含義:原本[0,5]可以調整為[2,7],在上面函數調用中的10處寫上2即可。

具體效果可以看figure2和figure3的對比,偏移了10個單位。

Steps:

1.load CSV files

result0 = pd.read_csv("mp_1.csv")

result1 = pd.read_csv("mp_2.csv")

result0 = result0.values

result1 = result1.values

the file:

first row: x data

second row: y data

third row: z data, which is to set the gradient color map.

2.set the size of map and the limits of x axis and y axis

#設置畫布

width_img = 5

height_img = 5

fig = plt.figure(figsize=(int(width_img)+2, int(height_img)+2),

facecolor='none')

ax = plt.gca()

#設置圖像上下界

plt.xlim(0,20)

plt.ylim(0,20)

3.draw color map

lc = paths.plot_results_path(result0,4)

lc2 = paths.plot_results_path(result1, 4)

4.draw colorbar

可以進行圖例colorbar刻度的調整,包括平移和比例放縮:

比例放縮的含義:原本[0,5]可以調整為[0,10],在下面函數調用中的result0[-1, 2]處寫上2即可;

平移的含義:原本[0,5]可以調整為[2,7],在下面函數調用中的10處寫上2即可;

cb = paths.plot_gd_bar(fig, ax, lc, result0[-1, 2], 10)

#最后兩個參數一個是調整比例,一個是調整偏移量

Notice:

plot_gd_bar(fig, ax, lc, result0[-1, 2], 10)

#最后兩個參數一個是調整比例,一個是調整偏移量

Notice:

以上方便修改和調整的是main.py和path_Result.py,gradient.py最好不要修改。

總結

以上是生活随笔為你收集整理的python怎么绘制渐变图_用Python画colorbar渐变图+修改刻度大小+修改渐变颜色的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。