Plotting#
# voltage data
voltage_trace = [
-42.11, -55.63, -59.04, -78.63, -62.77, -63.55, -60.83, -66.27, -60.44, -64.77, -73.14, -51.15, -51.19, -42.90, -59.50, -64.05, -65.45, -75.46, -50.18, -71.01, -71.85, -62.06, -45.14, -57.63, -70.24, -67.13, -53.75, -61.61, -67.69, -62.30, -52.55, -40.24, -72.44, -66.26, -68.04, 15.81, -69.24, -70.24, -48.76, -61.32, -76.23, -53.53, -63.56, 22.57, -65.97, -65.89, -68.74, -59.70, -82.48, -62.68, -49.87, -51.47, -48.92, -48.81, -45.12, -71.18, -51.54, -78.61, -66.03, -79.14, -49.52, -46.66, -61.97, -42.25, -66.75, 41.51, -58.47, -70.64, -55.62, -40.61, -70.25, -51.01, -61.55, -42.30, -55.16, -53.24, -53.57, -57.51, -73.96, -46.08, -73.71, -57.61, -53.86, -68.38, -58.55, -48.32, -60.24, -68.89, -89.16, -69.72, -65.91, -65.16, -69.60, 43.77, -65.75, -61.09, 46.79, -68.55, -63.00, -38.42, -51.26, -72.94, -60.80, -54.36, -47.67, -58.51, -65.31, -67.31, -53.55, -56.87, -65.17, -61.89, -64.16, -52.75, -66.90, -55.14, -51.48, -55.14, -68.34, -46.55, -66.78, -55.74, -67.53, -77.44, -57.74, -57.13, -60.77, 42.76, -66.48, -67.37, -61.68, -40.91, -51.85, -65.20, -54.41, -64.78, -64.57, -51.41, -65.25, -76.76, 30.94, -59.12, -58.72, -47.58, -67.16, -52.69, -55.74, -61.49, -51.64, 44.92, -68.62, -49.28, -72.21, -59.40, -59.98, -55.75, -67.25, -60.35, -61.41, -50.03, -67.96, -59.27, -62.61, -72.98, -33.24, -60.71, -74.87, -45.91, -70.71, -56.29, -51.37, -66.48, -64.31, -65.40, -61.29, -76.22, -72.36, -61.41, -49.61, -53.68, 57.29, -53.06, -65.11, -61.23, -80.30, -69.61, -70.20, -57.29, -53.52, -65.60, -65.89, -75.47, -61.28, -57.52, 44.46, -67.83, -40.12, -48.05, -60.95, -65.27, -63.22, -58.49, -60.19, -55.16, 47.69, -46.34, -48.53, -61.10, -56.12, -63.87, -65.87, -40.89, -64.60, -40.09, -63.49, -57.47, -49.11, -59.76, -56.07, -62.41, -64.76, -61.66, -66.50, -43.69, -61.68, -42.77, -86.85, -59.82, -54.38, -62.94, -49.05, -53.60, -62.75, -55.65, -31.88, -57.48, -57.00, -64.40, -58.67, -72.89, -61.98, -35.42, -49.33, -53.59, -48.96, -41.18, -54.06, -39.29, -49.30, -58.33, -42.81, -83.59, -65.71, 42.66, -69.12, -61.56, -66.39, -66.54, -32.88, -53.73, -60.54, 53.15, -62.37, -51.15, 43.51, -43.73, -74.20, -52.34, -58.78, -71.57, -49.35, -68.72, -43.81, -54.87, -53.05, 40.80, -50.95, -78.66, -59.25, -66.28, -57.17, -60.47, -53.83, -68.38, -41.61, -36.84, -62.08, -60.15, -57.12, -47.36, -41.03, -72.06, -66.15, -70.62, -71.13, -76.39, -56.37, -71.59, -44.97, -50.92, -70.30, -70.30, -66.12, -46.00, -68.50, -74.94, -60.49, -56.27, -66.57, -43.81, -57.60, -55.47, -68.56, -60.40, -61.57, -82.72, -57.12, 22.05, -60.29, -74.74, -39.80, -56.74, -51.39, -50.81, -73.24, -82.82, 36.70, -51.03, -59.09, -52.15, -50.63, -74.92, -57.12, -40.34, -65.71, -80.29, -62.32, -64.65, -55.82, -68.92, -59.09, -82.17, -51.46, -44.13, -47.02, -75.15, -56.81, -89.84, -57.17, -60.64, -69.96, -56.56, -58.62, -50.60, -58.73, -57.65, -79.45, -71.60, -64.76, -57.03, -60.06, -44.99, 31.30, -62.40, -57.45, -62.31, -55.04, -65.71, 54.20, -63.20, -48.84, -60.30, -45.08, -73.98, -54.83, -64.33, -57.69, -48.07, -71.39, -73.22, -69.98, -57.46, -78.87, 40.97, -72.86, -71.44, 36.31, -56.19, 33.74, -64.92, -60.42, -62.73, -86.77, -64.30, 40.85, -49.02, -39.54, 46.67, -59.21, -69.65, -59.11, -52.21, -47.35, -68.81, -57.64, -51.84, 58.61, -57.44, -65.42, -66.90, -63.57, -66.52, -51.73, -49.31, -52.75, -48.08, 35.46, -56.20, -63.85, 40.44, -47.75, -60.30, -78.65, -62.53, -67.13, -75.09, -67.90, 49.61, -43.19, -64.89, -49.97, 51.78, -71.60, -60.39, -60.44, -58.28, -75.94, -63.49, -49.42, -47.38, 58.31, -63.38, -41.30, -53.34, -73.59, -52.38, -63.52, -54.81, -61.03, 52.08, -57.43, -62.83, -50.35, -57.44, -64.13, -47.23, -64.08, -66.37, 34.60, -74.65, -65.53, -41.39, -69.08, -59.92, -71.08, 33.89, -44.81, -51.04, -66.10, -59.94, -68.26, -67.84, -69.15, -68.97, -56.74, 45.97, -55.12, 38.31, -73.58, -60.67, -69.24, -51.19, -54.44, 47.47, -63.48, -78.11, -50.42, -47.74, -74.83, -58.62, -48.07, -70.76, -42.32, -63.49, -70.75, -46.28, 42.95, -66.53, -51.20, -79.56, -41.85, -68.16, -57.14, -63.99, -55.64, 48.88, -68.24, -52.14, -62.94, -66.88, -62.24, -70.05, -67.96, -50.51, -61.51, 51.42, -55.68, -70.26, -78.98, 33.13, -57.36, -59.91, -68.30, -49.87, -77.46, -72.59, -58.73, -38.06, -55.86, -70.05, -54.07, -53.17, -50.62, -64.10, -68.00, -58.82, -55.85, -44.02, -39.10, -67.33, -65.23, -60.64, -62.50, -55.14, -55.14, -57.42, 53.44, -61.59, -70.51, -75.61, 29.72, -70.44, -78.83, 46.63, -58.15, 35.77, -68.90, 24.19, -69.20, -41.52, -82.11, -58.58, -52.56, -58.64, -63.17, -52.32, -71.03, -54.44, 54.31, -70.41, -68.20, -58.64, -50.10, -46.61, -53.19, -66.70, -71.14, -57.57, -56.02, -71.01, -59.40, -56.68, -49.55, -69.91, -54.43, -71.69, 35.73, -60.78, 55.18, -26.86, -57.46, -55.05, -49.92, -73.62, -52.34, 27.58, -43.71, -45.57, -54.98, 31.93, -43.32, -57.40, -58.90, -54.20, -77.12, -55.72, -50.04, -56.61, 41.45, -69.54, -53.56, -58.00, -59.91, -65.63, -51.44, -47.53, -56.12, -51.03, -46.74, -44.12, 42.26, -62.13, -64.15, 40.14, -54.48, -50.62, -64.27, 41.50, -69.97, -47.36, -63.91, -56.42, -67.19, -62.98, -66.86, -42.95, -56.41, -61.66, -69.48, -66.10, -54.31, 56.66, -74.31, -69.17, -61.76, 33.72, -76.59, 40.19, -52.49, -75.77, -57.89, -50.35, -50.20, 35.80, -36.95, -54.45, -68.11, -50.16, -71.23, -51.05, -72.62, -52.09, -65.84, -48.68, -52.59, -55.53, -59.41, -49.13, -78.03, -55.67, -55.87, -54.38, -51.74, -22.98, -58.83, -51.96, -58.48, -44.27, -80.21, -43.02, 33.16, -82.62, -70.78, -61.75, -58.06, -60.46, -51.83, -60.35, -60.63, -81.44, -55.13, -49.90, -64.21, -78.77, -73.37, -43.26, -66.06, -66.65, -68.19, -53.19, -65.88, -68.69, -75.06, -61.08, -49.99, -61.48, -51.18, -58.25, -58.52, -58.21, -59.66, -49.74, -55.12, -65.78, -58.71, -60.76, -55.15, -58.20, -55.85, -74.77, -56.20, -46.86, -73.50, -43.99, -57.03, -62.08, -78.04, -49.12, -69.70, -65.11, -54.54, -70.26, -69.87, -71.51, -61.11, -54.11, -55.97, -55.93, -63.44, -58.60, -66.90, -40.02, -58.05, -79.55, -70.69, -43.99, -73.66, -64.38, -55.96, -70.97, -49.33, -43.21, -68.25, -48.71, -68.91, -69.98, -57.54, -57.62, -65.96, -51.58, -74.69, -68.56, -70.78, -52.42, -51.96, -53.33, -72.96, -58.67, -55.42, -76.17, 31.78, -53.54, -52.96, -57.45, -54.58, -56.76, -58.50, -61.09, -68.71, -62.46, -64.03, -36.82, -57.40, -60.11, -62.32, -61.15, -62.72, -54.55, -60.29, -51.89, -66.95, -56.50, -51.23, -71.54, -58.32, -57.53, -63.35, -64.87, -78.55, -48.51, -69.33, -72.40, -53.42, -78.32, -50.37, -55.66, -54.02, -61.64, -72.17, -78.89, -45.43, -64.72, -65.17, -44.18, -66.31, -62.38, -62.37, -61.37, -70.39, -65.60, -47.15, -52.39, -89.77, -79.59, -56.66, -61.13, -63.75, -49.57, -77.84, -48.00, -58.68, -54.52, -57.47, -51.54, -62.50, -65.42, -52.18, -58.25, -72.54, -46.50, -47.89, -45.59, -59.20, -56.49, -63.82, -69.73, -59.35, -58.23, -66.63, -41.70, -76.16, -68.15, -66.71, -47.09, -62.57, -63.25, -68.85, -67.64, -73.05, -49.84, -53.91, -50.10, -66.62, -34.88, -69.81, -80.54, -62.92, -58.63, 47.56, -70.17, -54.09, -42.92, -68.52, -67.40, -77.03, -57.59, -51.43, -52.33, -51.66, -45.84, -58.73, -50.47, -69.52, -67.91, -57.59, -68.18, -54.28, -46.25, -55.96, -67.37, -67.48, -46.35, -67.98, -59.11, -62.59, -59.47, -49.04, -65.39, -74.10, -45.48, -57.77, -52.74, -60.19, -52.22, -47.35, -46.34, -62.73, -63.52, -56.05, -57.93, -54.34, -67.11, -83.25, -55.50, -52.19, -53.57, -43.41, -51.48, -63.88, -50.15, -60.85, -47.45, -57.62, -55.46, -57.72, -59.45, -74.97, -59.42, -82.73, -55.02, -50.08, -39.49, -56.26, -67.16, -75.90, -40.52, -74.26, -51.04, -83.06, -60.51, -53.17, -56.75, -60.42, -68.25, -69.07, -49.91, -55.64, -61.61, -57.93, -69.27, -49.78, -47.39, -67.80, -58.98, -49.52, -66.42, -39.65, -44.89, -62.79, -50.21, -43.38, -72.44, -53.81, -61.44, -62.17, -52.90, -64.77, -74.00, -74.22, -60.20, -53.71, -60.24, -61.53, -60.31, -47.11, -54.70, -67.46, -62.89, -47.95, -65.80, -63.95, -60.25, -70.65, -50.98, -81.89, -45.49, -64.35, -72.57, -57.18, -77.11, -54.63, -52.26, -65.76, -63.89, -50.51, -66.71, -59.77, -56.52, -44.40, -65.03,
]
# time point for each value in voltage_trace
times_seconds = [
0.0, 0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01, 0.011, 0.012, 0.013, 0.014, 0.015, 0.016, 0.017, 0.018, 0.019, 0.02, 0.021, 0.022, 0.023, 0.024, 0.025, 0.026, 0.027, 0.028, 0.029, 0.03, 0.031, 0.032, 0.033, 0.034, 0.035, 0.036, 0.037, 0.038, 0.039, 0.04, 0.041, 0.042, 0.043, 0.044, 0.045, 0.046, 0.047, 0.048, 0.049, 0.05, 0.051, 0.052, 0.053, 0.054, 0.055, 0.056, 0.057, 0.058, 0.059, 0.06, 0.061, 0.062, 0.063, 0.064, 0.065, 0.066, 0.067, 0.068, 0.069, 0.07, 0.071, 0.072, 0.073, 0.074, 0.075, 0.076, 0.077, 0.078, 0.079, 0.08, 0.081, 0.082, 0.083, 0.084, 0.085, 0.086, 0.087, 0.088, 0.089, 0.09, 0.091, 0.092, 0.093, 0.094, 0.095, 0.096, 0.097, 0.098, 0.099, 0.1, 0.101, 0.102, 0.103, 0.104, 0.105, 0.106, 0.107, 0.108, 0.109, 0.11, 0.111, 0.112, 0.113, 0.114, 0.115, 0.116, 0.117, 0.118, 0.119, 0.12, 0.121, 0.122, 0.123, 0.124, 0.125, 0.126, 0.127, 0.128, 0.129, 0.13, 0.131, 0.132, 0.133, 0.134, 0.135, 0.136, 0.137, 0.138, 0.139, 0.14, 0.141, 0.142, 0.143, 0.144, 0.145, 0.146, 0.147, 0.148, 0.149, 0.15, 0.151, 0.152, 0.153, 0.154, 0.155, 0.156, 0.157, 0.158, 0.159, 0.16, 0.161, 0.162, 0.163, 0.164, 0.165, 0.166, 0.167, 0.168, 0.169, 0.17, 0.171, 0.172, 0.173, 0.174, 0.175, 0.176, 0.177, 0.178, 0.179, 0.18, 0.181, 0.182, 0.183, 0.184, 0.185, 0.186, 0.187, 0.188, 0.189, 0.19, 0.191, 0.192, 0.193, 0.194, 0.195, 0.196, 0.197, 0.198, 0.199, 0.2, 0.201, 0.202, 0.203, 0.204, 0.205, 0.206, 0.207, 0.208, 0.209, 0.21, 0.211, 0.212, 0.213, 0.214, 0.215, 0.216, 0.217, 0.218, 0.219, 0.22, 0.221, 0.222, 0.223, 0.224, 0.225, 0.226, 0.227, 0.228, 0.229, 0.23, 0.231, 0.232, 0.233, 0.234, 0.235, 0.236, 0.237, 0.238, 0.239, 0.24, 0.241, 0.242, 0.243, 0.244, 0.245, 0.246, 0.247, 0.248, 0.249, 0.25, 0.251, 0.252, 0.253, 0.254, 0.255, 0.256, 0.257, 0.258, 0.259, 0.26, 0.261, 0.262, 0.263, 0.264, 0.265, 0.266, 0.267, 0.268, 0.269, 0.27, 0.271, 0.272, 0.273, 0.274, 0.275, 0.276, 0.277, 0.278, 0.279, 0.28, 0.281, 0.282, 0.283, 0.284, 0.285, 0.286, 0.287, 0.288, 0.289, 0.29, 0.291, 0.292, 0.293, 0.294, 0.295, 0.296, 0.297, 0.298, 0.299, 0.3, 0.301, 0.302, 0.303, 0.304, 0.305, 0.306, 0.307, 0.308, 0.309, 0.31, 0.311, 0.312, 0.313, 0.314, 0.315, 0.316, 0.317, 0.318, 0.319, 0.32, 0.321, 0.322, 0.323, 0.324, 0.325, 0.326, 0.327, 0.328, 0.329, 0.33, 0.331, 0.332, 0.333, 0.334, 0.335, 0.336, 0.337, 0.338, 0.339, 0.34, 0.341, 0.342, 0.343, 0.344, 0.345, 0.346, 0.347, 0.348, 0.349, 0.35, 0.351, 0.352, 0.353, 0.354, 0.355, 0.356, 0.357, 0.358, 0.359, 0.36, 0.361, 0.362, 0.363, 0.364, 0.365, 0.366, 0.367, 0.368, 0.369, 0.37, 0.371, 0.372, 0.373, 0.374, 0.375, 0.376, 0.377, 0.378, 0.379, 0.38, 0.381, 0.382, 0.383, 0.384, 0.385, 0.386, 0.387, 0.388, 0.389, 0.39, 0.391, 0.392, 0.393, 0.394, 0.395, 0.396, 0.397, 0.398, 0.399, 0.4, 0.401, 0.402, 0.403, 0.404, 0.405, 0.406, 0.407, 0.408, 0.409, 0.41, 0.411, 0.412, 0.413, 0.414, 0.415, 0.416, 0.417, 0.418, 0.419, 0.42, 0.421, 0.422, 0.423, 0.424, 0.425, 0.426, 0.427, 0.428, 0.429, 0.43, 0.431, 0.432, 0.433, 0.434, 0.435, 0.436, 0.437, 0.438, 0.439, 0.44, 0.441, 0.442, 0.443, 0.444, 0.445, 0.446, 0.447, 0.448, 0.449, 0.45, 0.451, 0.452, 0.453, 0.454, 0.455, 0.456, 0.457, 0.458, 0.459, 0.46, 0.461, 0.462, 0.463, 0.464, 0.465, 0.466, 0.467, 0.468, 0.469, 0.47, 0.471, 0.472, 0.473, 0.474, 0.475, 0.476, 0.477, 0.478, 0.479, 0.48, 0.481, 0.482, 0.483, 0.484, 0.485, 0.486, 0.487, 0.488, 0.489, 0.49, 0.491, 0.492, 0.493, 0.494, 0.495, 0.496, 0.497, 0.498, 0.499, 0.5, 0.501, 0.502, 0.503, 0.504, 0.505, 0.506, 0.507, 0.508, 0.509, 0.51, 0.511, 0.512, 0.513, 0.514, 0.515, 0.516, 0.517, 0.518, 0.519, 0.52, 0.521, 0.522, 0.523, 0.524, 0.525, 0.526, 0.527, 0.528, 0.529, 0.53, 0.531, 0.532, 0.533, 0.534, 0.535, 0.536, 0.537, 0.538, 0.539, 0.54, 0.541, 0.542, 0.543, 0.544, 0.545, 0.546, 0.547, 0.548, 0.549, 0.55, 0.551, 0.552, 0.553, 0.554, 0.555, 0.556, 0.557, 0.558, 0.559, 0.56, 0.561, 0.562, 0.563, 0.564, 0.565, 0.566, 0.567, 0.568, 0.569, 0.57, 0.571, 0.572, 0.573, 0.574, 0.575, 0.576, 0.577, 0.578, 0.579, 0.58, 0.581, 0.582, 0.583, 0.584, 0.585, 0.586, 0.587, 0.588, 0.589, 0.59, 0.591, 0.592, 0.593, 0.594, 0.595, 0.596, 0.597, 0.598, 0.599, 0.6, 0.601, 0.602, 0.603, 0.604, 0.605, 0.606, 0.607, 0.608, 0.609, 0.61, 0.611, 0.612, 0.613, 0.614, 0.615, 0.616, 0.617, 0.618, 0.619, 0.62, 0.621, 0.622, 0.623, 0.624, 0.625, 0.626, 0.627, 0.628, 0.629, 0.63, 0.631, 0.632, 0.633, 0.634, 0.635, 0.636, 0.637, 0.638, 0.639, 0.64, 0.641, 0.642, 0.643, 0.644, 0.645, 0.646, 0.647, 0.648, 0.649, 0.65, 0.651, 0.652, 0.653, 0.654, 0.655, 0.656, 0.657, 0.658, 0.659, 0.66, 0.661, 0.662, 0.663, 0.664, 0.665, 0.666, 0.667, 0.668, 0.669, 0.67, 0.671, 0.672, 0.673, 0.674, 0.675, 0.676, 0.677, 0.678, 0.679, 0.68, 0.681, 0.682, 0.683, 0.684, 0.685, 0.686, 0.687, 0.688, 0.689, 0.69, 0.691, 0.692, 0.693, 0.694, 0.695, 0.696, 0.697, 0.698, 0.699, 0.7, 0.701, 0.702, 0.703, 0.704, 0.705, 0.706, 0.707, 0.708, 0.709, 0.71, 0.711, 0.712, 0.713, 0.714, 0.715, 0.716, 0.717, 0.718, 0.719, 0.72, 0.721, 0.722, 0.723, 0.724, 0.725, 0.726, 0.727, 0.728, 0.729, 0.73, 0.731, 0.732, 0.733, 0.734, 0.735, 0.736, 0.737, 0.738, 0.739, 0.74, 0.741, 0.742, 0.743, 0.744, 0.745, 0.746, 0.747, 0.748, 0.749, 0.75, 0.751, 0.752, 0.753, 0.754, 0.755, 0.756, 0.757, 0.758, 0.759, 0.76, 0.761, 0.762, 0.763, 0.764, 0.765, 0.766, 0.767, 0.768, 0.769, 0.77, 0.771, 0.772, 0.773, 0.774, 0.775, 0.776, 0.777, 0.778, 0.779, 0.78, 0.781, 0.782, 0.783, 0.784, 0.785, 0.786, 0.787, 0.788, 0.789, 0.79, 0.791, 0.792, 0.793, 0.794, 0.795, 0.796, 0.797, 0.798, 0.799, 0.8, 0.801, 0.802, 0.803, 0.804, 0.805, 0.806, 0.807, 0.808, 0.809, 0.81, 0.811, 0.812, 0.813, 0.814, 0.815, 0.816, 0.817, 0.818, 0.819, 0.82, 0.821, 0.822, 0.823, 0.824, 0.825, 0.826, 0.827, 0.828, 0.829, 0.83, 0.831, 0.832, 0.833, 0.834, 0.835, 0.836, 0.837, 0.838, 0.839, 0.84, 0.841, 0.842, 0.843, 0.844, 0.845, 0.846, 0.847, 0.848, 0.849, 0.85, 0.851, 0.852, 0.853, 0.854, 0.855, 0.856, 0.857, 0.858, 0.859, 0.86, 0.861, 0.862, 0.863, 0.864, 0.865, 0.866, 0.867, 0.868, 0.869, 0.87, 0.871, 0.872, 0.873, 0.874, 0.875, 0.876, 0.877, 0.878, 0.879, 0.88, 0.881, 0.882, 0.883, 0.884, 0.885, 0.886, 0.887, 0.888, 0.889, 0.89, 0.891, 0.892, 0.893, 0.894, 0.895, 0.896, 0.897, 0.898, 0.899, 0.9, 0.901, 0.902, 0.903, 0.904, 0.905, 0.906, 0.907, 0.908, 0.909, 0.91, 0.911, 0.912, 0.913, 0.914, 0.915, 0.916, 0.917, 0.918, 0.919, 0.92, 0.921, 0.922, 0.923, 0.924, 0.925, 0.926, 0.927, 0.928, 0.929, 0.93, 0.931, 0.932, 0.933, 0.934, 0.935, 0.936, 0.937, 0.938, 0.939, 0.94, 0.941, 0.942, 0.943, 0.944, 0.945, 0.946, 0.947, 0.948, 0.949, 0.95, 0.951, 0.952, 0.953, 0.954, 0.955, 0.956, 0.957, 0.958, 0.959, 0.96, 0.961, 0.962, 0.963, 0.964, 0.965, 0.966, 0.967, 0.968, 0.969, 0.97, 0.971, 0.972, 0.973, 0.974, 0.975, 0.976, 0.977, 0.978, 0.979, 0.98, 0.981, 0.982, 0.983, 0.984, 0.985, 0.986, 0.987, 0.988, 0.989, 0.99, 0.991, 0.992, 0.993, 0.994, 0.995, 0.996, 0.997, 0.998, 0.999
]
print(len(times_seconds), len(voltage_trace))
1000 1000
Plotting is not part of core python - we have to use an external library for that: Matplotlib.
Matplotlib comes installed with the anaconda distribution and the pyplot module is the most user-friendly way of plotting in python.
To make it available in the notebook, we need to “import” it. What you need to know for now (More details on how to work with external libraries next week):
import matplotlib.pyplot as plt
This adds the pyplot module of matplotlib to your notebook’s namespace and makes all functions in matplotlib.pyplot
available via the plt
shortcut:
import matplotlib.pyplot as plt # "Load" pyplot
plt.plot(voltage_trace) # plot the voltage traces (list of voltage values)
plt.show() # show the plot here

By default, pyplot produces reasonably useful plots - but we can tweak and annotate them to make them even better.
It helps to know how different elements of a figure are referred to in matplotlib: Figure, axes, x and y axis, x and y axis labels, title, x and y axis tick marks and tick labels.
Figure size and annotations - figsize, xlabel, ylabel, title#
plt.figure(figsize=(12, 1.5)) # create a figure with a 1:10 aspect ratio
plt.plot(voltage_trace) # plot the voltage trace
# add labels
plt.ylabel('Membrane voltage [mV]') # label the y axis
plt.xlabel('Sample') # label the x axis
plt.title('Data') # plot title
plt.show()

Change colors#
See here for more information on specifying colors: https://matplotlib.org/stable/gallery/color/named_colors.html
plt.figure(figsize=(12, 1.5)) # create a figure with a 1:10 aspect ratio
plt.plot(voltage_trace, c='r') # change the color by providing single letter, one of rgbcymwk
plt.show()
plt.figure(figsize=(12, 1.5)) # create a figure with a 1:10 aspect ratio
plt.plot(voltage_trace, c='dodgerblue') # by color name (see link above)
plt.show()


Specify x values#
plt.figure(figsize=(12, 1.5))
plt.plot(times_seconds, voltage_trace) # use seconds as x-values
plt.show()

Change axis limits - xlim, ylim#
plt.figure(figsize=(12, 1.5))
plt.plot(times_seconds, voltage_trace, 'k')
plt.ylabel('Membrane voltage [mV]')
plt.xlabel('Time [s]')
plt.title('Subthreshold voltages')
# plt.ylim(-80, -20) # set limits of y axis
plt.xlim(0.4, 0.6) # set only lower limit of x axis
plt.show()

Change x and y tick marks and labels - xticks and yticks#
plt.figure(figsize=(12, 1.5))
plt.plot(times_seconds, voltage_trace, 'k')
plt.xticks([0, 0.5, 1]) # specify tick marks on x-axis
plt.yticks([-80, -40, 0, 40, 60], labels=[-80, -40, "ZERO", 40, 60]) # change tick marks and labels on y-axis
plt.ylabel('Membrane voltage [mV]')
plt.xlabel('Time [s]')
plt.show()

Change and combine markers#
plt.figure(figsize=(12, 1.5))
plt.plot(times_seconds, voltage_trace, 'o-', c='k') # plot voltage traces as lines and dots
plt.ylabel('Membrane voltage [mV]')
plt.xlabel('Time [s]')
plt.title('Recording')
plt.show()

Overlay multiple plots#
plt.figure(figsize=(12, 1.5))
plt.plot(times_seconds, voltage_trace, '-', c='k') # voltage trace as line in black
plt.plot(times_seconds, voltage_trace, 'o', c='r', alpha=0.2) # individual voltage values as dots, `alpha` controls opacity
plt.ylabel('Membrane voltage [mV]') # label the y axis
plt.xlabel('Time [s]') # label the y axis
plt.title('Recording')
plt.show()

Multi-panel figures - subplot#
plt.figure(figsize=(20, 4))
plt.subplot(2, 10, 1) # first panel = axes
plt.plot(times_seconds, voltage_trace, 'k')
plt.subplot(2, 10, 2) # second panel = axes
plt.plot(times_seconds, voltage_trace, 'k')
plt.ylim(-90, -30)
plt.show()

Legends#
plt.figure(figsize=(12, 1.5))
plt.plot(times_seconds, voltage_trace, 'o', c='r', alpha=0.2, label='data') # define legend label
plt.legend() # add the legend - alternatively: plt.legend(['line', 'dots'])
plt.plot(times_seconds, voltage_trace, '-', c='k', label='line') # define legend label
plt.ylabel('Membrane voltage [mV]') # label the y axis
plt.xlabel('Time [s]') # label the y axis
plt.title('Recording')
plt.show()
