我想在具有多种颜色的散点图中添加图例而不是颜色栏。
我正在寻找类似this的散点图。 我当前的图形如下所示:
我想知道是否可以像在第二个子图中那样在第一个子图中添加图例而不是颜色条。
创建散点图的函数:
def scatter_it(x): # x=8 für Monate, x=9 für Jahre
"""Punktdiagramm mit farblicher Markierung der Monate bzw. Jahre."""
plt.figure("Station: {0}, Monat(e): {1}, Jahr(e):{2}".format(Station,months,years))
plt.style.use('seaborn-whitegrid')
if x == 8:
# setting a standard color as first color of cmap rainbow
farben = plt.cm.get_cmap('rainbow', 13)
newcolors = farben(np.linspace(0, 1, 13))
b = np.array([31/256, 19/256, 180/256, 1]) # standard color # blue: 31/119/180 # black: 0/0/0
newcolors[:1, :] = b
newcmp = ListedColormap(newcolors)
cmap = newcmp
else:
cmap = 'tab20'
plt.subplot(2, 1, 1)
plt.title("Art der Korrelation: Kendalls ${\mathrm{T}}_b$\n" +
"Korrelation: " + str(r_tp[0]) +
"\np-Wert (2-seitig): " + str(r_tp[1]) +
"\nStation: {0}, Monat(e): {1}, Jahr(e):{2}\n".format(Station,months,years),
loc='left', wrap=True)
sct = plt.scatter(master_arrayFilter[:,1], # Marsdistanz (in AE)
master_arrayFilter[:,2], # Temperatur (in °C)
c=master_arrayFilter[:,x], # Monate bzw. Jahre
cmap=plt.cm.get_cmap(cmap, np.unique(master_arrayFilter[:,x])[-1]+1-np.unique(master_arrayFilter[:,x])[0]),
#teilt die colormap rainbow_r od. tab20 in n (=max-min) benötigte Abschnitte auf #leider auch in ggf. nicht benötigte Zwischenschritte
vmin = master_arrayFilter[np.argmin(master_arrayFilter[:,x], axis=0),x]-.5,
#vmin gibt unteres Ende der Skala an und setzt die Markierung mittig
vmax = master_arrayFilter[np.argmax(master_arrayFilter[:,x], axis=0),x]+.5)
#vmax gibt oberes Ende der Skala an und setzt die Markierung mittig
plt.xlabel("Marsdistanz in AE\n(1 AE = 149.597.870,7 km)")
plt.ylabel("Temperatur in °C") #für Niderschlag bzw. Sonnenstunden anpassen.
#plt.tight_layout()
clb = plt.colorbar(sct, ticks=np.arange(master_arrayFilter[np.argmin(master_arrayFilter[:,x], axis=0),x]-1,
master_arrayFilter[np.argmax(master_arrayFilter[:,x], axis=0),x])+1)
if x == 8:
y = "Monat(e)"
else:
y = "Jahr(e)"
clb.ax.set_title(y)
# z = np.unique(master_arrayFilter[:,x])
# def make_proxy(zvalue, **kwargs):
# color = cmap
# return Line2D([0, 1], [0, 1], color=color, **kwargs)
# proxies = [make_proxy(item, linewidth=2) for item in z]
# plt.legend(proxies, [str(int(x)) for x in months],
# loc='upper right', frameon=True, title=y)
plt.subplot(2, 1, 2)
if not months:
md_plot(master_array[:,0], master_array[:,1]) # Graph
minmaxmarker(master_array[:,0], master_array[:,1]) # Punkte
else:
md_plot3(master_array[:,0], master_array[:,1], master_array[:,8], months) # Graph mit Färbung
minmaxmarker(master_array[:,0], master_array[:,1]) # Punkte
md_plot2(master_array[:,0], master_array[:,1], master_array[:,6]) # Graph mit Färbung
minmaxmarker(master_array[:,0], master_array[:,1]) # Punkte
plt.show()
plt.close()
return None
我禁用了尝试但失败的内容。
以下是二手master_array
的摘录:
In [211]: print(master_array)
[[ 1.89301010e+07 1.23451036e+00 -8.10000000e+00 ... 1.00000000e+00
1.00000000e+00 1.89300000e+03]
[ 1.89301020e+07 1.24314818e+00 -8.50000000e+00 ... 2.00000000e+00
1.00000000e+00 1.89300000e+03]
[ 1.89301030e+07 1.25179997e+00 -9.70000000e+00 ... 3.00000000e+00
1.00000000e+00 1.89300000e+03]
...
[ 2.01903100e+07 1.84236878e+00 7.90000000e+00 ... 1.00000000e+01
3.00000000e+00 2.01900000e+03]
[ 2.01903110e+07 1.85066892e+00 5.50000000e+00 ... 1.10000000e+01
3.00000000e+00 2.01900000e+03]
[ 2.01903120e+07 1.85894904e+00 9.40000000e+00 ... 1.20000000e+01
3.00000000e+00 2.01900000e+03]]
答案 0 :(得分:0)
由于您的示例依赖于某些外部变量,因此创建了另一个示例。在调用散点标签参数期间进行设置,然后可以直接调用df1 <-structure(list(col1 = c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L
), col2 = c(6.5, 12, 9, 16.2, 7.5, 13, 6, 2.8, 26, 30)),
class = "data.frame", row.names = c(NA,
-10L))
:
security:
encoders:
App\Entity\Users:
algorithm: bcrypt
providers:
users:
entity:
class: App\Entity\Users
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login_app_manager:
pattern: ^/user/login
stateless: true
anonymous: true
provider: users
json_login:
check_path: /user/login
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
require_previous_session: false
app_api_manager:
pattern: ^/mngr/api
stateless: true
anonymous: false
provider: users
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
var data = {
'email':email,
'password':password
};
$.ajax({
type: "POST",
url: "/user/login",
contentType: "application/json",
data: JSON.stringify(data),
success: function(response) {
console.log(response);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log('Error : ' + errorThrown);
}
});