Problem with surface plot color and legend

This page summarizes the projects mentioned and recommended in the original post on /r/learnpython

InfluxDB - Power Real-Time Data Analytics at Scale
Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
www.influxdata.com
featured
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  • matplotlib

    matplotlib: plotting with Python

  • # https://old.reddit.com/r/learnpython/comments/r1etmt/problem_with_surface_plot_color_and_legend/ # AmericaRL_03.py # Comparação entre random walk e difusão em 1d import numpy as np import matplotlib.pyplot as plt M = 100000 # Número de walkers L = 100 # Tamanho da malha # A cada intervalo de tempo, mover o walker e propagar a difusão p = 0.1 # Probabilidade de andar pinv = 1.0 - p nsteps = 2001 # Número de intervalos de tempo # Iniciando as concentrações c = np.zeros((2, 2 * L + 1, 2 * L + 1)) i0 = 0 i1 = 1 c[:, L, L] = M # c[:,L,L] corresponde a (x,y) = (0,0) edgesdiff = np.array(range(-L - 1, L + 1)) - 0.5 xc = 0.5 * (edgesdiff[:-1] + edgesdiff[1:]) xx, yy = np.meshgrid(xc, xc) D = p noutput = 100 for it in range(nsteps): # Executar a etapa na equação de difusão for ix in range(1, len(c[0]) - 1): for iy in range(1, len(c[0]) - 1): # Usar i0 e gerar i1 c[i1, ix, iy] = c[i0, ix, iy] + D * ( c[i0, ix - 1, iy] + c[i0, ix + 1, iy] - 4 * c[i0, ix, iy] + c[i0, ix, iy - 1] + c[i0, ix, iy + 1] ) # Inverter i0 e i1 ii = i1 i1 = i0 i0 = ii # Plotar as concentrações if np.mod(it, noutput) == 0: fig = plt.figure() ax = fig.add_subplot(111, projection="3d") # ax.cla() diff = ax.plot_surface(xx, yy, c[0, :, :], cmap="Reds", label="Difusão") plt.title("Tempo = {}, M = {}, p = {}".format(it, M, p)) ax.set_xlabel("Distância percorrida (x)") ax.set_ylabel("Distância percorrida (y)") ax.set_zlabel("Concentração") # ax.legend() fails getting proper label key color in 3D plots # # AttributeError missing _facecolors2d and _edgecolors2d are raised # in 3D projection method get_facecolor() used by legend handler # # Is open issue since 2015 # https://github.com/matplotlib/matplotlib/issues/4067 if False: # OP's way: Set values manually to keep legend() quiet diff._facecolors2d = diff._facecolor3d diff._edgecolors2d = diff._edgecolor3d ax.legend() # But then problems with legend() getting proper legend key color # default (blue) is used instead of a value from set cmap (Reds) else: # DIFFERENT FIX: Draw legend key and legend label manually # # First get suitable cmap color (instead blue default) # https://stackoverflow.com/a/25408562 from matplotlib.cm import get_cmap cmap = get_cmap('Reds') my_red_rgba = cmap(0.5) # e.g. a color in middle of range (0..1) # Then insert own artist for legend key and legend label # https://matplotlib.org/stable/tutorials/intermediate/legend_guide.html import matplotlib.patches as mpatches red_patch = mpatches.Patch(color=my_red_rgba, label='Difusão') ax.legend(handles=[red_patch]) # plt.show() plt.savefig('tempo_{}.png'.format(it),dpi = 600) plt.pause(0.001) ax.cla() # is nicer placed here instead above

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Achivments for You Commits

    1 project | news.ycombinator.com | 8 May 2024
  • Your 14-Day Free Trial Ain't Gonna Cut It

    3 projects | news.ycombinator.com | 6 May 2024
  • FLaNK-AIM Weekly 06 May 2024

    45 projects | dev.to | 6 May 2024
  • I've made game engine (I think)

    2 projects | dev.to | 5 May 2024
  • Análise barragens - parte 2

    1 project | dev.to | 5 May 2024